diff --git a/src/backend.c b/src/backend.c
index c95a6741ae..ad1d19d913 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -25,10 +25,11 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_backend_class_entry;
+zend_class_entry *git_backend_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_read, 0, 0, 1)
     ZEND_ARG_INFO(0, key)
@@ -60,13 +61,14 @@ int php_git_backend__exists(git_odb_backend *_backend, const git_oid *oid)
     TSRMLS_FETCH();
     php_git_backend_internal *object = (php_git_backend_internal *)_backend;
     char out[GIT_OID_HEXSZ+1] = {0};
-    git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
 
     zval *retval;
     zval *params[1];
     zval func;
     int result;
 
+    git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
+
     MAKE_STD_ZVAL(retval);
     ZVAL_NULL(retval);
     ZVAL_STRING(&func,"exists", 1);
@@ -97,19 +99,22 @@ int php_git_backend__write(git_oid *id, git_odb_backend *_backend, git_rawobj *o
     zval *retval;
     zval *params[1];
     zval func;
+    php_git_rawobject_t *raw;
+
     MAKE_STD_ZVAL(retval);
     ZVAL_NULL(retval);
     ZVAL_STRING(&func,"write", 1);
 
 
     MAKE_STD_ZVAL(params[0]);
-    object_init_ex(params[0],git_rawobject_class_entry);
-    
+    object_init_ex(params[0], git_rawobject_class_entry);
+
     add_property_stringl_ex(params[0],"data",sizeof("data"),obj->data,obj->len,1 TSRMLS_CC);
     add_property_long(params[0],"type",obj->type);
     add_property_long(params[0],"len",obj->len);
 
-    php_git_rawobject_t *raw = (php_git_rawobject_t *) zend_object_store_get_object(params[0] TSRMLS_CC);
+
+    raw = (php_git_rawobject_t *) zend_object_store_get_object(params[0] TSRMLS_CC);
     raw->object = obj;
 
     if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){
@@ -123,7 +128,7 @@ int php_git_backend__write(git_oid *id, git_odb_backend *_backend, git_rawobj *o
     }else{
         ret = GIT_ERROR;
     }
-    
+
     zval_ptr_dtor(&retval);
     //do not free Git\RawObject here.
     //zval_ptr_dtor(&params[0]);
@@ -135,12 +140,14 @@ int php_git_backend__read(git_rawobj *obj, git_odb_backend *_backend, const git_
 {
     TSRMLS_FETCH();
     php_git_backend_internal *object = (php_git_backend_internal *)_backend;
-    char out[GIT_OID_HEXSZ+1] = {0};
-    git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
+    char out[GIT_OID_HEXSZ+1] = {0};   
 
     zval *retval;
     zval *params[1];
     zval func;
+    zval *str;
+
+    git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
 
     MAKE_STD_ZVAL(retval);
     ZVAL_NULL(retval);
@@ -161,18 +168,18 @@ int php_git_backend__read(git_rawobj *obj, git_odb_backend *_backend, const git_
         return GIT_ENOTFOUND;
     }
 
-    zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC);
-    
+    str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC);
+
     // do not use ecalloc. obj->data will free by git_rawobject_close()
     obj->data = calloc(1,strlen(Z_STRVAL_P(str)));
     obj->len = strlen(Z_STRVAL_P(str));
     obj->type = GIT_OBJ_BLOB;
     memcpy(obj->data, Z_STRVAL_P(str),obj->len);
-    
+
     zval_ptr_dtor(&retval);
     zval_ptr_dtor(&params[0]);
     zval_dtor(&func);
-    
+
     return GIT_SUCCESS;
 }
 int php_git_backend__read_header(git_rawobj *obj, git_odb_backend *_backend, const git_oid *oid)
@@ -180,11 +187,13 @@ int php_git_backend__read_header(git_rawobj *obj, git_odb_backend *_backend, con
     TSRMLS_FETCH();
     char out[GIT_OID_HEXSZ+1] = {0} ;
     php_git_backend_internal *object = (php_git_backend_internal *)_backend;
-    git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
 
     zval *retval;
     zval *params[1];
     zval func;
+    zval *str;
+
+    git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
 
     MAKE_STD_ZVAL(retval);
     ZVAL_NULL(retval);
@@ -205,20 +214,20 @@ int php_git_backend__read_header(git_rawobj *obj, git_odb_backend *_backend, con
         return GIT_ENOTFOUND;
     }
 
-    zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",sizeof("data"), 0 TSRMLS_CC);
-    
+    str = zend_read_property(git_rawobject_class_entry, retval,"data",sizeof("data"), 0 TSRMLS_CC);
+
     obj->data = NULL;
     obj->len = strlen(Z_STRVAL_P(str));
     obj->type = GIT_OBJ_BLOB;
-    
+
     zval_ptr_dtor(&retval);
     zval_ptr_dtor(&params[0]);
     zval_dtor(&func);
-    
+
     return GIT_SUCCESS;
 }
 
-void php_git_backend__free(git_odb_backend *backend)
+int php_git_backend__free(git_odb_backend *backend)
 {
     TSRMLS_FETCH();
     php_git_backend_internal *object = (php_git_backend_internal *)backend;
@@ -239,6 +248,8 @@ void php_git_backend__free(git_odb_backend *backend)
 
     zval_ptr_dtor(&retval);
     zval_dtor(&func);
+
+    return 1;
 }
 
 zend_object_value php_git_backend_new(zend_class_entry *ce TSRMLS_DC)
@@ -278,7 +289,7 @@ PHP_METHOD(git_backend, __construct)
     this->backend = internal;
 }
 
-PHPAPI function_entry php_git_backend_methods[] = {
+static zend_function_entry php_git_backend_methods[] = {
     PHP_ME(git_backend, __construct, NULL,    ZEND_ACC_PUBLIC)
     PHP_ABSTRACT_ME(git_backend, read,        arginfo_git_backend_read)
     PHP_ABSTRACT_ME(git_backend, read_header, arginfo_git_backend_read_header)
diff --git a/src/blob.c b/src/blob.c
index a46e066e70..597732601f 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -28,7 +28,7 @@
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_blob_class_entry;
+zend_class_entry *git_blob_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob__construct, 0, 0, 1)
     ZEND_ARG_INFO(0, repository)
@@ -41,7 +41,7 @@ ZEND_END_ARG_INFO()
 static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC)
 {
     zend_object_std_dtor(&obj->zo TSRMLS_CC);
-    
+
     //obj->object will free by git_repository.
     obj->object = NULL;
     efree(obj);
@@ -49,21 +49,21 @@ static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC)
 
 zend_object_value php_git_blob_new(zend_class_entry *ce TSRMLS_DC)
 {
-	zend_object_value retval;
-	php_git_repository_t *obj;
-	zval *tmp;
+    zend_object_value retval;
+    php_git_repository_t *obj;
+    zval *tmp;
 
-	obj = ecalloc(1, sizeof(*obj));
-	zend_object_std_init( &obj->zo, ce TSRMLS_CC );
-	zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+    obj = ecalloc(1, sizeof(*obj));
+    zend_object_std_init( &obj->zo, ce TSRMLS_CC );
+    zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
 
-	retval.handle = zend_objects_store_put(obj, 
+    retval.handle = zend_objects_store_put(obj, 
         (zend_objects_store_dtor_t)zend_objects_destroy_object,
         (zend_objects_free_object_storage_t)php_git_blob_free_storage,
         NULL TSRMLS_CC);
-	retval.handlers = zend_get_std_object_handlers();
+    retval.handlers = zend_get_std_object_handlers();
 
-	return retval;
+    return retval;
 }
 
 
@@ -71,16 +71,19 @@ zend_object_value php_git_blob_new(zend_class_entry *ce TSRMLS_DC)
 PHP_METHOD(git_blob, __construct)
 {
     zval *z_repository;
+    php_git_repository_t *git;
+    php_git_blob_t     *obj;
+    int ret;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "z", &z_repository) == FAILURE){
         return;
     }
 
-    php_git_repository_t *git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC);
-    php_git_blob_t *obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
-    
-    int ret = git_blob_new(&obj->object,git->repository);
+    git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC);
+    obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+
+    ret = git_blob_new(&obj->object,git->repository);
 
     if(ret != GIT_SUCCESS){
         php_error_docref(NULL TSRMLS_CC, E_WARNING,"Can't create new blob!");
@@ -93,15 +96,17 @@ PHP_METHOD(git_blob, setContent)
 {
     char *string;
     size_t string_len = 0;
+    php_git_blob_t *obj;
+    int ret;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &string, &string_len) == FAILURE){
         return;
     }
 
-    php_git_blob_t *obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+    obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
 
-    int ret = git_blob_set_rawcontent(obj->object,string, string_len);
+    ret = git_blob_set_rawcontent(obj->object,string, string_len);
     if(ret != GIT_SUCCESS){
         php_error_docref(NULL TSRMLS_CC, E_WARNING,"Can't set content!");
         return;
@@ -109,7 +114,7 @@ PHP_METHOD(git_blob, setContent)
     add_property_string_ex(getThis(), "data", sizeof("data"),string, 1 TSRMLS_CC);
 }
 
-PHPAPI function_entry php_git_blob_methods[] = {
+zend_function_entry php_git_blob_methods[] = {
     PHP_ME(git_blob, __construct, arginfo_git_blob__construct, ZEND_ACC_PUBLIC)
     PHP_ME(git_blob, setContent, arginfo_git_blob_set_content, ZEND_ACC_PUBLIC)
     {NULL, NULL, NULL}
@@ -121,6 +126,6 @@ void git_init_blob(TSRMLS_D)
     INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Blob", php_git_blob_methods);
 
     git_blob_class_entry = zend_register_internal_class_ex(&ce, git_object_class_entry, NULL TSRMLS_CC);
-	git_blob_class_entry->create_object = php_git_blob_new;
+    git_blob_class_entry->create_object = php_git_blob_new;
 
 }
\ No newline at end of file
diff --git a/src/commit.c b/src/commit.c
index 74cec9b488..abd608945d 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -31,7 +31,7 @@
 extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry);
 extern zend_object_value php_git_repository_new(zend_class_entry *ce TSRMLS_DC);
 
-PHPAPI zend_class_entry *git_commit_class_entry;
+zend_class_entry *git_commit_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit__construct, 0, 0, 1)
     ZEND_ARG_INFO(0, repository)
@@ -56,7 +56,7 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_message, 0, 0, 1)
     ZEND_ARG_INFO(0, message)
 ZEND_END_ARG_INFO()
-    
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_get_parent, 0, 0, 1)
     ZEND_ARG_INFO(0, offset)
 ZEND_END_ARG_INFO()
@@ -64,7 +64,7 @@ ZEND_END_ARG_INFO()
 static void php_git_commit_free_storage(php_git_commit_t *obj TSRMLS_DC)
 {
     zend_object_std_dtor(&obj->zo TSRMLS_CC);
-    
+
     //RepositoryでFreeされるよ
     obj->object = NULL;
     obj->repository = NULL;
@@ -73,20 +73,20 @@ static void php_git_commit_free_storage(php_git_commit_t *obj TSRMLS_DC)
 
 zend_object_value php_git_commit_new(zend_class_entry *ce TSRMLS_DC)
 {
-	zend_object_value retval;
-	php_git_commit_t *obj;
-	zval *tmp;
+    zend_object_value retval;
+    php_git_commit_t *obj;
+    zval *tmp;
 
-	obj = ecalloc(1, sizeof(*obj));
-	zend_object_std_init( &obj->zo, ce TSRMLS_CC );
-	zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+    obj = ecalloc(1, sizeof(*obj));
+    zend_object_std_init( &obj->zo, ce TSRMLS_CC );
+    zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
 
-	retval.handle = zend_objects_store_put(obj, 
+    retval.handle = zend_objects_store_put(obj, 
         (zend_objects_store_dtor_t)zend_objects_destroy_object,
         (zend_objects_free_object_storage_t)php_git_commit_free_storage,
         NULL TSRMLS_CC);
-	retval.handlers = zend_get_std_object_handlers();
-	return retval;
+    retval.handlers = zend_get_std_object_handlers();
+    return retval;
 }
 
 PHP_METHOD(git_commit, __construct)
@@ -96,16 +96,18 @@ PHP_METHOD(git_commit, __construct)
     git_repository *repository;
     zval *object = getThis();
     int ret;
+    php_git_commit_t *cobj;
+    php_git_repository_t *myobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "z", &z_repository) == FAILURE){
         return;
     }
     object_init_ex(object, git_commit_class_entry);
-    php_git_commit_t *cobj = (php_git_commit_t *) zend_object_store_get_object(object TSRMLS_CC);
-    php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC);
+    cobj = (php_git_commit_t *) zend_object_store_get_object(object TSRMLS_CC);
+    myobj = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC);
+
 
-    
     ret = git_commit_new(&commit,myobj->repository);
     if(ret != GIT_SUCCESS){
         //FIXME
@@ -208,13 +210,14 @@ PHP_METHOD(git_commit, setTree)
     git_repository *repository;
     git_object *git_obj;
     int attr;
+    php_git_commit_t *myobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &hash, &hash_len) == FAILURE){
         return;
     }
 
-    php_git_commit_t *myobj = (php_git_commit_t *) zend_object_store_get_object(object TSRMLS_CC);
+    myobj = (php_git_commit_t *) zend_object_store_get_object(object TSRMLS_CC);
     repository = myobj->repository;
 
     git_oid_mkstr(&oid, hash);
@@ -225,11 +228,7 @@ PHP_METHOD(git_commit, setTree)
         //コピペ
         zval *git_tree;
         zval *entries;
-        git_tree_entry *entry;
-        MAKE_STD_ZVAL(git_tree);
-        MAKE_STD_ZVAL(entries);
-        array_init(entries);
-        object_init_ex(git_tree, git_tree_class_entry);
+        git_tree_entry *entry;    
 
         int r = git_tree_entrycount(tree);
         int i = 0;
@@ -237,6 +236,11 @@ PHP_METHOD(git_commit, setTree)
         char *offset;
         const git_oid *moid;
         zval *array_ptr;
+    
+        MAKE_STD_ZVAL(git_tree);
+        MAKE_STD_ZVAL(entries);
+        array_init(entries);
+        object_init_ex(git_tree, git_tree_class_entry);
 
         for(i; i < r; i++){
             entry = git_tree_entry_byindex(tree,i);
@@ -285,7 +289,7 @@ PHP_METHOD(git_commit, getMessage)
 {
     php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     const char *message;
-    
+
     message = git_commit_message(this->object);
     RETURN_STRING(message,1);
 }
@@ -294,7 +298,7 @@ PHP_METHOD(git_commit, getShortMessage)
 {
     php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     const char *message;
-    
+
     message = git_commit_message_short(this->object);
     RETURN_STRING(message,1);
 }
@@ -303,23 +307,26 @@ PHP_METHOD(git_commit, getTree)
 {
     php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     git_tree *ref_tree;
+    const git_oid *oid;
+    git_tree *tree;
+    int ret;
+    git_oid *tree_oid;
+    zval *git_tree;
+    zval *entry;
+    php_git_tree_t *tobj;
+
     git_commit_tree(&ref_tree, this->object);
-    const git_oid *oid = 	git_object_id((git_object*)ref_tree);
+    oid = git_object_id((git_object*)ref_tree);
 
-    git_tree *tree;
-    int ret = git_object_lookup((git_object **)&tree, git_object_owner((git_object*)this->object),oid, GIT_OBJ_TREE);
+    ret = git_object_lookup((git_object **)&tree, git_object_owner((git_object*)this->object),oid, GIT_OBJ_TREE);
     if(ret != GIT_SUCCESS) {
         php_error_docref(NULL TSRMLS_CC, E_ERROR, "specified tree not found.");
         return;
-    }
-
-    git_oid *tree_oid;
-    zval *git_tree;
-    zval *entry;
+    }   
 
     MAKE_STD_ZVAL(git_tree);
     object_init_ex(git_tree, git_tree_class_entry);
-    php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC);
+    tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC);
     tobj->object = tree;
 
 /*
@@ -360,14 +367,14 @@ PHP_METHOD(git_commit, getParent)
         "|l", &offset) == FAILURE){
         return;
     }
-    
+
     ret = git_commit_parent(&commit, this->object,offset);
     if(ret != GIT_SUCCESS){
         php_error_docref(NULL TSRMLS_CC, E_ERROR, "specified offset not found.");
         RETURN_FALSE;
     }
 
-    
+
     MAKE_STD_ZVAL(zcommit);
     object_init_ex(zcommit,git_commit_class_entry);
     obj = (php_git_commit_t *) zend_object_store_get_object(zcommit TSRMLS_CC);
@@ -375,7 +382,7 @@ PHP_METHOD(git_commit, getParent)
 
     create_signature_from_commit(&author, git_commit_author(obj->object));
     create_signature_from_commit(&committer, git_commit_committer(obj->object));
-    
+
     add_property_zval(zcommit,"author", author);
     add_property_zval(zcommit,"committer", committer);
 
@@ -386,7 +393,7 @@ PHP_METHOD(git_commit, getParent)
     efree(committer);
 }
 
-PHPAPI function_entry php_git_commit_methods[] = {
+static zend_function_entry php_git_commit_methods[] = {
     PHP_ME(git_commit, __construct,     arginfo_git_commit__construct,   ZEND_ACC_PUBLIC)
     PHP_ME(git_commit, setTree,         arginfo_git_commit_set_tree,     ZEND_ACC_PUBLIC)
     PHP_ME(git_commit, getTree,         NULL,                            ZEND_ACC_PUBLIC)
@@ -408,7 +415,7 @@ void git_init_commit(TSRMLS_C)
     INIT_NS_CLASS_ENTRY(git_commit_ce, PHP_GIT_NS,"Commit", php_git_commit_methods);
 
     git_commit_class_entry = zend_register_internal_class_ex(&git_commit_ce,git_object_class_entry,NULL TSRMLS_CC);
-	git_commit_class_entry->create_object = php_git_commit_new;
+    git_commit_class_entry->create_object = php_git_commit_new;
     zend_declare_property_null(git_commit_class_entry, "author",   sizeof("author")-1,    ZEND_ACC_PUBLIC TSRMLS_CC);
     zend_declare_property_null(git_commit_class_entry, "committer",sizeof("committer")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
 }
\ No newline at end of file
diff --git a/src/config.w32 b/src/config.w32
new file mode 100644
index 0000000000..843afa7f91
--- /dev/null
+++ b/src/config.w32
@@ -0,0 +1,16 @@
+// $Id$
+// vim:ft=javascript
+
+ARG_ENABLE("git", "for git support", "no");
+
+if (PHP_GIT != "no") {
+    if (CHECK_HEADER_ADD_INCLUDE("git2.h", "CFLAGS_GIT", PHP_GIT) &&
+        CHECK_LIB("git2.lib", "git", PHP_GIT) &&
+        CHECK_LIB("libgit2.lib", "git", PHP_GIT)
+    ) {
+        AC_DEFINE('HAVE_GIT', 1);
+        EXTENSION('git', 'php_git.c walker.c tree_iterator.c tree_entry.c tree.c tag.c signature.c repository.c reference_manager.c reference.c rawobject.c odb.c object.c index_iterator.c index_entry.c index.c commit.c blob.c backend.c');
+    } else {
+        WARNING("phpgit not enabled; libraries and/or headers not found");
+    }
+}
\ No newline at end of file
diff --git a/src/index.c b/src/index.c
index 9b3b1ed787..8f127ee35d 100644
--- a/src/index.c
+++ b/src/index.c
@@ -25,11 +25,12 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_index_class_entry;
-PHPAPI zend_class_entry *git_index_iterator_class_entry;
+zend_class_entry *git_index_class_entry;
+zend_class_entry *git_index_iterator_class_entry;
 
 static void php_git_index_free_storage(php_git_index_t *obj TSRMLS_DC)
 {
@@ -91,9 +92,9 @@ ZEND_END_ARG_INFO()
 
 void php_git_index_entry_create(zval **index, git_index_entry *entry)
 {
-    TSRMLS_FETCH();
-    MAKE_STD_ZVAL(*index);
+    TSRMLS_FETCH();    
     char oid[GIT_OID_HEXSZ+1] = {0};
+	MAKE_STD_ZVAL(*index);
     object_init_ex(*index,git_index_entry_class_entry);
     git_oid_to_string(oid,GIT_OID_HEXSZ+1,&entry->oid);
 
@@ -127,13 +128,14 @@ PHP_METHOD(git_index, find)
     git_index *index = NULL;
     git_index_entry *entry;
     zval *z_git_index_entry;
+	php_git_index_t *myobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &path, &path_len) == FAILURE){
         return;
     }
 
-    php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+    myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     index = myobj->index;
 
     offset = git_index_find(index,path);
@@ -175,20 +177,22 @@ PHP_METHOD(git_index, add)
     int path_len = 0;
     git_index *index = NULL;
     long stage = 0;
+	php_git_index_t *myobj;
+	int success;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s|l", &path, &path_len, &stage) == FAILURE){
         return;
     }
 
-    php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+    myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     index = myobj->index;
 
     //FIXME: examine stage value.
     // 0 => new file
     // 1 => deleted ?
     // 2 => ?
-    int success = git_index_add(index,path,stage);
+    success = git_index_add(index,path,stage);
     if(success != GIT_SUCCESS){
         zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
             "can't add specified index.");
@@ -203,20 +207,22 @@ PHP_METHOD(git_index, remove)
     php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     char *path;
     int path_len = 0;
+	int offset;
+	int result;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &path, &path_len) == FAILURE){
         return;
     }
 
-    int offset = git_index_find(this->index,path);
+    offset = git_index_find(this->index,path);
     if(offset < 0){
         zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
             "specified path does not exist.");
         RETURN_FALSE;
     }
 
-    int result = git_index_remove(this->index, offset);
+    result = git_index_remove(this->index, offset);
     if(result != GIT_SUCCESS){
         zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
             "specified offset does not exist.");
@@ -254,10 +260,11 @@ PHP_METHOD(git_index, getIterator)
 {
     php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     zval *iterator;
+	php_git_index_iterator_t *obj;
     
     MAKE_STD_ZVAL(iterator);
     object_init_ex(iterator,git_index_iterator_class_entry);
-    php_git_index_iterator_t *obj = (php_git_index_iterator_t *) zend_object_store_get_object(iterator TSRMLS_CC);
+    obj = (php_git_index_iterator_t *) zend_object_store_get_object(iterator TSRMLS_CC);
     obj->index = this->index;
     obj->offset = 0;
     RETURN_ZVAL(iterator,0,0);
@@ -317,7 +324,7 @@ PHP_METHOD(git_index, insert)
 }
 */
 
-PHPAPI function_entry php_git_index_methods[] = {
+static zend_function_entry php_git_index_methods[] = {
     //PHP_ME(git_index, __construct, arginfo_git_index__construct,ZEND_ACC_PUBLIC)
     PHP_ME(git_index, getEntry,    arginfo_git_index_get_entry, ZEND_ACC_PUBLIC)
     PHP_ME(git_index, find,        arginfo_git_index_find,      ZEND_ACC_PUBLIC)
diff --git a/src/index_entry.c b/src/index_entry.c
index f1a21bc2a8..755f10ef52 100644
--- a/src/index_entry.c
+++ b/src/index_entry.c
@@ -28,7 +28,7 @@
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_index_entry_class_entry;
+zend_class_entry *git_index_entry_class_entry;
 
 static void php_git_index_entry_free_storage(php_git_index_entry_t *obj TSRMLS_DC)
 {
@@ -56,7 +56,7 @@ zend_object_value php_git_index_entry_new(zend_class_entry *ce TSRMLS_DC)
     return retval;
 }
 
-PHPAPI function_entry php_git_index_entry_methods[] = {
+static zend_function_entry php_git_index_entry_methods[] = {
     {NULL, NULL, NULL}
 };
 
diff --git a/src/index_iterator.c b/src/index_iterator.c
index 08477cdc59..2d72309c9b 100644
--- a/src/index_iterator.c
+++ b/src/index_iterator.c
@@ -25,11 +25,12 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 
 
-PHPAPI zend_class_entry *git_index_iterator_class_entry;
+zend_class_entry *git_index_iterator_class_entry;
 extern void php_git_index_entry_create(zval **index, git_index_entry *entry);
 
 static void php_git_index_iterator_free_storage(php_git_index_iterator_t *obj TSRMLS_DC)
@@ -112,18 +113,19 @@ PHP_METHOD(git_index_iterator, __construct)
 {
     php_git_index_iterator_t *this = (php_git_index_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     zval *php_git_index;
+	php_git_index_t *idx;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "z", &php_git_index) == FAILURE){
         return;
     }
-    php_git_index_t *idx = (php_git_index_t *) zend_object_store_get_object(php_git_index TSRMLS_CC);
+    idx = (php_git_index_t *) zend_object_store_get_object(php_git_index TSRMLS_CC);
 
     this->index = idx->index;
     this->offset = 0;
 }
 
-PHPAPI function_entry php_git_index_iterator_methods[] = {
+static zend_function_entry php_git_index_iterator_methods[] = {
     PHP_ME(git_index_iterator, __construct, arginfo_git_index_iterator__construct,ZEND_ACC_PUBLIC)
     PHP_ME(git_index_iterator, current,     NULL,                        ZEND_ACC_PUBLIC)
     PHP_ME(git_index_iterator, key,         NULL,                        ZEND_ACC_PUBLIC)
diff --git a/src/object.c b/src/object.c
index d651e10fd8..953d26ef28 100644
--- a/src/object.c
+++ b/src/object.c
@@ -25,10 +25,11 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_object_class_entry;
+zend_class_entry *git_object_class_entry;
 
 static void php_git_object_free_storage(php_git_object_t *obj TSRMLS_DC)
 {
@@ -102,7 +103,7 @@ PHP_METHOD(git_object, write)
     RETVAL_STRING(out,1);
 }
 
-PHPAPI function_entry php_git_object_methods[] = {
+static zend_function_entry php_git_object_methods[] = {
     PHP_ME(git_object, getId,   NULL,ZEND_ACC_PUBLIC)
     PHP_ME(git_object, getType, NULL,ZEND_ACC_PUBLIC)
     PHP_ME(git_object, write,   NULL,ZEND_ACC_PUBLIC)
diff --git a/src/odb.c b/src/odb.c
index 4dfa12bd0c..47a29c809a 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -25,10 +25,11 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_odb_class_entry;
+zend_class_entry *git_odb_class_entry;
 
 int php_git_odb_add_backend(git_odb **odb, zval *backend, int priority);
 int php_git_odb_add_alternate(git_odb **odb, zval *backend, int priority);
@@ -150,7 +151,7 @@ PHP_METHOD(git_odb, addAlternate)
 }
 
 
-PHPAPI function_entry php_git_odb_methods[] = {
+static zend_function_entry php_git_odb_methods[] = {
     PHP_ME(git_odb, __construct, NULL, ZEND_ACC_PUBLIC)
     PHP_ME(git_odb, addBackend, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC)
     PHP_ME(git_odb, addAlternate, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC)
diff --git a/src/php_git.c b/src/php_git.c
index ff9b4243c1..050ce4938c 100644
--- a/src/php_git.c
+++ b/src/php_git.c
@@ -23,12 +23,13 @@
  */
 
 #include "php_git.h"
+#include <ext/standard/info.h>
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_class_entry;
+zend_class_entry *git_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_string_to_type, 0, 0, 1)
     ZEND_ARG_INFO(0, string_type)
@@ -108,12 +109,12 @@ PHP_FUNCTION(git_raw_to_hex)
     RETVAL_STRINGL(out,GIT_OID_HEXSZ,1);
 }
 
-PHPAPI function_entry php_git_methods[] = {
+static zend_function_entry php_git_methods[] = {
     {NULL, NULL, NULL}
 };
 
 // Git Global Functions
-PHPAPI function_entry php_git_functions[] = {
+static zend_function_entry php_git_functions[] = {
     PHP_FE(git_hex_to_raw, arginfo_git_hex_to_raw)
     PHP_FE(git_raw_to_hex, arginfo_git_raw_to_hex)
     PHP_FE(git_type_to_string, arginfo_git_type_to_string)
@@ -121,6 +122,7 @@ PHPAPI function_entry php_git_functions[] = {
     {NULL, NULL, NULL}
 };
 
+
 void git_init(TSRMLS_D)
 {
     zend_class_entry git_ce;
@@ -179,12 +181,12 @@ zend_module_entry git_module_entry = {
     STANDARD_MODULE_HEADER,
 #endif
     PHP_GIT_EXTNAME,
-    php_git_functions,	/* Functions */
-    PHP_MINIT(git),	/* MINIT */
-    NULL, 	/* MSHUTDOWN */
-    NULL, 	/* RINIT */
-    NULL,	/* RSHUTDOWN */
-    PHP_MINFO(git),	/* MINFO */
+    php_git_functions,    /* Functions */
+    PHP_MINIT(git),    /* MINIT */
+    NULL,     /* MSHUTDOWN */
+    NULL,     /* RINIT */
+    NULL,    /* RSHUTDOWN */
+    PHP_MINFO(git),    /* MINFO */
 #if ZEND_MODULE_API_NO >= 20010901
     PHP_GIT_EXTVER,
 #endif
diff --git a/src/php_git.h b/src/php_git.h
index b8d9834a50..36f558e0ff 100644
--- a/src/php_git.h
+++ b/src/php_git.h
@@ -33,6 +33,16 @@
 #include "config.h"
 #endif
 
+#ifdef PHP_WIN32
+#define PHP_GIT_API __declspec(dllexport)
+#else
+#define PHP_GIT_API
+#endif
+
+#ifdef ZTS
+#include "TSRM.h"
+#endif
+
 #include "php.h"
 #include "ext/spl/spl_exceptions.h"
 #include <git2.h>
@@ -45,25 +55,45 @@ extern zend_module_entry git_module_entry;
 #define phpext_git_ptr &git_module_entry;
 #define PHP_GIT_NS "Git"
 
-extern PHPAPI zend_class_entry *git_class_entry;
-extern PHPAPI zend_class_entry *git_reference_class_entry;
-extern PHPAPI zend_class_entry *git_reference_manager_class_entry;
-extern PHPAPI zend_class_entry *git_repository_class_entry;
-extern PHPAPI zend_class_entry *git_object_class_entry;
-extern PHPAPI zend_class_entry *git_index_class_entry;
-extern PHPAPI zend_class_entry *git_index_iterator_class_entry;
-extern PHPAPI zend_class_entry *git_index_entry_class_entry;
-extern PHPAPI zend_class_entry *git_walker_class_entry;
-extern PHPAPI zend_class_entry *git_tree_class_entry;
-extern PHPAPI zend_class_entry *git_tree_iterator_class_entry;
-extern PHPAPI zend_class_entry *git_tree_entry_class_entry;
-extern PHPAPI zend_class_entry *git_commit_class_entry;
-extern PHPAPI zend_class_entry *git_signature_class_entry;
-extern PHPAPI zend_class_entry *git_rawobject_class_entry;
-extern PHPAPI zend_class_entry *git_tag_class_entry;
-extern PHPAPI zend_class_entry *git_blob_class_entry;
-extern PHPAPI zend_class_entry *git_odb_class_entry;
-extern PHPAPI zend_class_entry *git_backend_class_entry;
+extern zend_class_entry *git_class_entry;
+extern zend_class_entry *git_reference_class_entry;
+extern zend_class_entry *git_reference_manager_class_entry;
+extern zend_class_entry *git_repository_class_entry;
+extern zend_class_entry *git_object_class_entry;
+extern zend_class_entry *git_index_class_entry;
+extern zend_class_entry *git_index_iterator_class_entry;
+extern zend_class_entry *git_index_entry_class_entry;
+extern zend_class_entry *git_walker_class_entry;
+extern zend_class_entry *git_tree_class_entry;
+extern zend_class_entry *git_tree_iterator_class_entry;
+extern zend_class_entry *git_tree_entry_class_entry;
+extern zend_class_entry *git_commit_class_entry;
+extern zend_class_entry *git_signature_class_entry;
+extern zend_class_entry *git_rawobject_class_entry;
+extern zend_class_entry *git_tag_class_entry;
+extern zend_class_entry *git_blob_class_entry;
+extern zend_class_entry *git_odb_class_entry;
+extern zend_class_entry *git_backend_class_entry;
+
+extern void git_init_backend(TSRMLS_D);
+extern void git_init_blob(TSRMLS_D);
+extern void git_init_commit(TSRMLS_D);
+extern void git_index_init(TSRMLS_D);
+extern void git_index_entry_init(TSRMLS_D);
+extern void git_index_iterator_init(TSRMLS_D);
+extern void git_init_object(TSRMLS_D);
+extern void git_init_odb(TSRMLS_D);
+extern void git_init_rawobject(TSRMLS_D);
+extern void git_init_reference(TSRMLS_D);
+extern void git_init_reference_manager(TSRMLS_D);
+extern void php_git_repository_init(TSRMLS_D);
+extern void git_init_tag(TSRMLS_D);
+extern void git_init_tree(TSRMLS_D);
+extern void git_init_tree_entry(TSRMLS_D);
+extern void git_tree_iterator_init(TSRMLS_D);
+extern void git_init_signature(TSRMLS_D);
+extern void git_init_walker(TSRMLS_D);
+
 
 typedef struct{
     zend_object zo;
diff --git a/src/rawobject.c b/src/rawobject.c
index caf30e670e..0b53726aea 100644
--- a/src/rawobject.c
+++ b/src/rawobject.c
@@ -28,7 +28,7 @@
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_rawobject_class_entry;
+zend_class_entry *git_rawobject_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_rawobject_set_content, 0, 0, 1)
     ZEND_ARG_INFO(0, string)
@@ -81,12 +81,13 @@ PHP_METHOD(git_raw_object, __construct)
     int data_len = 0;
     int type = 0;
     int len = 0;
+    php_git_rawobject_t *this;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "lsl", &type, &data, &data_len, &len) == FAILURE){
         return;
     }
-    php_git_rawobject_t *this= (php_git_rawobject_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+    this = (php_git_rawobject_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     this->object = emalloc(sizeof(git_rawobj));
     this->object->data = NULL;
     this->object->type = type;
@@ -112,7 +113,7 @@ PHP_METHOD(git_raw_object, getId)
 }
 
 
-PHPAPI function_entry php_git_rawobject_methods[] = {
+static zend_function_entry php_git_rawobject_methods[] = {
     PHP_ME(git_raw_object, __construct, arginfo_git_rawobject__construct, ZEND_ACC_PUBLIC)
     PHP_ME(git_raw_object, getId,       NULL,                             ZEND_ACC_PUBLIC)
     {NULL, NULL, NULL}
@@ -124,5 +125,5 @@ void git_init_rawobject(TSRMLS_D)
     INIT_NS_CLASS_ENTRY(git_rawobject_ce, PHP_GIT_NS,"RawObject", php_git_rawobject_methods);
 
     git_rawobject_class_entry = zend_register_internal_class(&git_rawobject_ce TSRMLS_CC);
-	git_rawobject_class_entry->create_object = php_git_rawobject_new;
+    git_rawobject_class_entry->create_object = php_git_rawobject_new;
 }
\ No newline at end of file
diff --git a/src/reference.c b/src/reference.c
index c5c9f77503..aeca71e9a2 100644
--- a/src/reference.c
+++ b/src/reference.c
@@ -28,9 +28,9 @@
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_reference_class_entry;
+zend_class_entry *git_reference_class_entry;
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_set_name, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_rename, 0, 0, 1)
     ZEND_ARG_INFO(0, name)
 ZEND_END_ARG_INFO()
 
@@ -41,11 +41,11 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_set_oid, 0, 0, 1)
     ZEND_ARG_INFO(0, oid)
 ZEND_END_ARG_INFO()
-
+/*
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference__construct, 0, 0, 1)
     ZEND_ARG_INFO(0, repository)
 ZEND_END_ARG_INFO()
-    
+*/  
 static void php_git_reference_free_storage(php_git_reference_t *obj TSRMLS_DC)
 {
     if(obj->object){
@@ -111,7 +111,7 @@ PHP_METHOD(git_reference, getName)
     RETVAL_STRING(name, 1);
 }
 
-PHP_METHOD(git_reference, setName)
+PHP_METHOD(git_reference, rename)
 {
     php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     char *name;
@@ -122,10 +122,10 @@ PHP_METHOD(git_reference, setName)
         return;
     }
 
-    git_reference_set_name(this->object, name);
+    git_reference_rename(this->object, name);
     add_property_string_ex(getThis() ,"name",sizeof("name"),name, 1 TSRMLS_CC);
 }
-
+/*
 PHP_METHOD(git_reference, write)
 {
     php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
@@ -137,6 +137,7 @@ PHP_METHOD(git_reference, write)
     }
     RETURN_TRUE;
 }
+*/
 
 
 PHP_METHOD(git_reference, setTarget)
@@ -171,7 +172,7 @@ PHP_METHOD(git_reference, setOID)
     git_reference_set_oid(this->object, &out);
     add_property_string_ex(getThis() ,"oid",sizeof("oid"),oid, 1 TSRMLS_CC);
 }
-
+/*
 PHP_METHOD(git_reference, __construct)
 {
     php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
@@ -210,7 +211,7 @@ PHP_METHOD(git_reference, __construct)
         this->object = refs;
     }
 }
-
+*/
 PHP_METHOD(git_reference, getId)
 {
     php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
@@ -221,14 +222,14 @@ PHP_METHOD(git_reference, getId)
     RETURN_STRINGL(&out,GIT_OID_HEXSZ, 1);
 }
 
-PHPAPI function_entry php_git_reference_methods[] = {
-    PHP_ME(git_reference, __construct, arginfo_git_reference__construct, ZEND_ACC_PUBLIC)
+static zend_function_entry php_git_reference_methods[] = {
+    //PHP_ME(git_reference, __construct, arginfo_git_reference__construct, ZEND_ACC_PUBLIC)
     PHP_ME(git_reference, getTarget,   NULL, ZEND_ACC_PUBLIC)
     PHP_ME(git_reference, getType,     NULL, ZEND_ACC_PUBLIC)
     PHP_ME(git_reference, getName,     NULL, ZEND_ACC_PUBLIC)
     PHP_ME(git_reference, getId,       NULL, ZEND_ACC_PUBLIC)
-    PHP_ME(git_reference, write,       NULL, ZEND_ACC_PUBLIC)
-    PHP_ME(git_reference, setName,     arginfo_git_reference_set_name, ZEND_ACC_PUBLIC)
+    //PHP_ME(git_reference, write,       NULL, ZEND_ACC_PUBLIC)
+    PHP_ME(git_reference, rename,     arginfo_git_reference_rename, ZEND_ACC_PUBLIC)
     PHP_ME(git_reference, setTarget,   arginfo_git_reference_set_target, ZEND_ACC_PUBLIC)
     PHP_ME(git_reference, setOID,      arginfo_git_reference_set_oid, ZEND_ACC_PUBLIC)
     {NULL, NULL, NULL}
diff --git a/src/reference_manager.c b/src/reference_manager.c
index ce216df59a..1bb3422564 100644
--- a/src/reference_manager.c
+++ b/src/reference_manager.c
@@ -25,11 +25,12 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 #undef lookup
 
-PHPAPI zend_class_entry *git_reference_manager_class_entry;
+zend_class_entry *git_reference_manager_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_manager__construct, 0, 0, 1)
     ZEND_ARG_INFO(0, repository)
@@ -73,6 +74,7 @@ PHP_METHOD(git_reference_manager, __construct)
 {
     php_git_reference_manager_t *this= (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     zval *repository;
+	php_git_repository_t *repo;
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "z", &repository) == FAILURE){
         return;
@@ -82,7 +84,7 @@ PHP_METHOD(git_reference_manager, __construct)
              "argument does not Git\\Repository");
         RETURN_FALSE;
     }
-    php_git_repository_t *repo = (php_git_repository_t *) zend_object_store_get_object(repository TSRMLS_CC);
+    repo = (php_git_repository_t *) zend_object_store_get_object(repository TSRMLS_CC);
     if(repo->repository == NULL){
         zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
              "repository didn't ready");
@@ -108,6 +110,7 @@ PHP_METHOD(git_reference_manager, getList)
     array_init(references);
     for(i = 0; i < list->count; i++){
         zval *ref;
+		php_git_reference_t *refobj;
 
         // FIXME
         result = git_reference_lookup(&reference, this->repository, list->strings[i]);
@@ -119,18 +122,19 @@ PHP_METHOD(git_reference_manager, getList)
 
         MAKE_STD_ZVAL(ref);
         object_init_ex(ref, git_reference_class_entry);
-        php_git_reference_t *refobj  = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
+        refobj  = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
         refobj->object = reference;
 
         add_property_string_ex(ref,"name",  sizeof("name"),  (char *)git_reference_name(reference), 1 TSRMLS_CC);
 
         type = git_reference_type(reference);
         if(type == GIT_REF_SYMBOLIC) {
+			int rr;
             const char *target = git_reference_target(reference);
             if(target != NULL) {
                 add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC);
             }
-            int rr = git_reference_resolve(&refobj->object,reference);
+            rr = git_reference_resolve(&refobj->object,reference);
             if(rr != GIT_SUCCESS){
                 zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
                     "something wrong");
@@ -173,6 +177,7 @@ PHP_METHOD(git_reference_manager, lookup)
     git_oid *oid;
     git_rtype type;
     git_reference *reference;
+	php_git_reference_t *refobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &name, &name_len) == FAILURE){
@@ -188,18 +193,19 @@ PHP_METHOD(git_reference_manager, lookup)
 
     MAKE_STD_ZVAL(ref);
     object_init_ex(ref, git_reference_class_entry);
-    php_git_reference_t *refobj  = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
+    refobj  = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
     refobj->object = reference;
 
     add_property_string_ex(ref,"name",  sizeof("name"),  (char *)git_reference_name(reference), 1 TSRMLS_CC);
 
     type = git_reference_type(reference);
     if(type == GIT_REF_SYMBOLIC) {
+		int rr;
         const char *target = git_reference_target(reference);
         if(target != NULL) {
             add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC);
         }
-        int rr = git_reference_resolve(&refobj->object,reference);
+        rr = git_reference_resolve(&refobj->object,reference);
         if(rr != GIT_SUCCESS){
             zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
                 "something wrong");
@@ -221,6 +227,13 @@ PHP_METHOD(git_reference_manager, create)
     char *oid;
     int oid_len = 0;
     git_oid id;
+	git_odb *odb;
+	git_reference *reference;
+	int ret;
+	char out[GIT_OID_HEXSZ+1] = {0};
+    git_rtype type;
+    zval *ref;
+	php_git_reference_t *refobj;
     
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "ss", &name, &name_len, &oid, &oid_len) == FAILURE){
@@ -232,40 +245,36 @@ PHP_METHOD(git_reference_manager, create)
         RETURN_FALSE;
     }
     
-    git_oid_mkstr(&id, oid);
-    git_odb *odb;
+    git_oid_mkstr(&id, oid);    
     odb = git_repository_database(this->repository);
     
     if(!git_odb_exists(odb,&id)){
         zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
             "specified oid not found");
         RETURN_FALSE;
-    }
+    }    
     
-    git_reference *reference;
-    int ret = git_reference_create_oid(&reference, this->repository, name, &id);
+    ret = git_reference_create_oid(&reference, this->repository, name, &id);
     if(ret != GIT_SUCCESS){
         zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
             "can't add reference");
         RETURN_FALSE;
-    }
+    }    
     
-    char out[GIT_OID_HEXSZ+1] = {0};
-    git_rtype type;
-    zval *ref;
     MAKE_STD_ZVAL(ref);
     object_init_ex(ref, git_reference_class_entry);
-    php_git_reference_t *refobj  = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
+    refobj = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
     refobj->object = reference;
 
     add_property_string_ex(ref,"name",  sizeof("name"),  name, 1 TSRMLS_CC);
     type = git_reference_type(reference);
     if(type == GIT_REF_SYMBOLIC) {
         const char *target = git_reference_target(reference);
+		int rr;
         if(target != NULL) {
             add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC);
         }
-        int rr = git_reference_resolve(&refobj->object,reference);
+        rr = git_reference_resolve(&refobj->object,reference);
         if(rr != GIT_SUCCESS){
             zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
                 "something wrong");
@@ -277,7 +286,7 @@ PHP_METHOD(git_reference_manager, create)
     RETURN_ZVAL(ref,0,0);
 }
 
-PHPAPI function_entry php_git_reference_manager_methods[] = {
+static zend_function_entry php_git_reference_manager_methods[] = {
     PHP_ME(git_reference_manager, __construct, arginfo_git_reference_manager__construct, ZEND_ACC_PUBLIC)
     PHP_ME(git_reference_manager, getList,     NULL, ZEND_ACC_PUBLIC)
     PHP_ME(git_reference_manager, lookup,   arginfo_git_reference_manager_lookup, ZEND_ACC_PUBLIC)
diff --git a/src/repository.c b/src/repository.c
index b20d234bf9..655256bd9d 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -25,10 +25,11 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_repository_class_entry;
+zend_class_entry *git_repository_class_entry;
 
 extern void create_signature_from_commit(zval **signature, const git_signature *sig);
 extern int php_git_odb_add_backend(git_odb **odb, zval *backend, int priority);
@@ -130,13 +131,15 @@ PHP_METHOD(git_repository, init)
     int is_bare = 0;
     int ret;
     zval *obj;
+	int suc;
+	php_git_repository_t *myobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"sl",
         &path, &path_len, &is_bare) == FAILURE){
         return;
     }
 
-    int suc = git_repository_init(&repository,path,is_bare);
+    suc = git_repository_init(&repository,path,is_bare);
 
     if(suc != GIT_SUCCESS){
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "can't create repository\n");
@@ -145,7 +148,7 @@ PHP_METHOD(git_repository, init)
     
     MAKE_STD_ZVAL(obj);
     object_init_ex(obj, git_repository_class_entry);
-    php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(obj TSRMLS_CC);
+    myobj = (php_git_repository_t *) zend_object_store_get_object(obj TSRMLS_CC);
     myobj->repository = repository;
 
     add_property_string_ex(obj, "path",sizeof("path"),path, 1 TSRMLS_CC);
@@ -160,6 +163,7 @@ PHP_METHOD(git_repository, getIndex)
 
     zval *index_object;
     int ret = 0;
+	php_git_index_t *iobj;
 
     php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC);
 
@@ -175,7 +179,7 @@ PHP_METHOD(git_repository, getIndex)
 
     MAKE_STD_ZVAL(index_object);
     object_init_ex(index_object, git_index_class_entry);
-    php_git_index_t *iobj = (php_git_index_t *) zend_object_store_get_object(index_object TSRMLS_CC);
+    iobj = (php_git_index_t *) zend_object_store_get_object(index_object TSRMLS_CC);
 
     iobj->index = index;
 
@@ -202,6 +206,8 @@ PHP_METHOD(git_repository, getObject)
     char *hash;
     int hash_len = 0;
     int ret = 0;
+	php_git_repository_t *myobj;
+	php_git_blob_t *blobobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &hash, &hash_len) == FAILURE){
@@ -210,7 +216,7 @@ PHP_METHOD(git_repository, getObject)
     
     git_oid_mkstr(&oid, hash);
     
-    php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC);
+    myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC);
     repository = myobj->repository;
     
     odb = git_repository_database(repository);
@@ -223,7 +229,7 @@ PHP_METHOD(git_repository, getObject)
         if(ret == GIT_SUCCESS){
             MAKE_STD_ZVAL(git_object);
             object_init_ex(git_object, git_blob_class_entry);
-            php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_object TSRMLS_CC);
+            blobobj = (php_git_blob_t *) zend_object_store_get_object(git_object TSRMLS_CC);
             blobobj->object = blob;
 
             git_rawsz = git_blob_rawsize(blob);
@@ -241,9 +247,11 @@ void create_tree_entry_from_entry(zval **object, git_tree_entry *entry)
     TSRMLS_FETCH();
     char buf[41] = {0};
     const git_oid *oid;
+	php_git_tree_entry_t *entry_obj;
+	
     MAKE_STD_ZVAL(*object);
     object_init_ex(*object, git_tree_entry_class_entry);
-    php_git_tree_entry_t *entry_obj = (php_git_tree_entry_t *) zend_object_store_get_object(*object TSRMLS_CC);
+    entry_obj = (php_git_tree_entry_t *) zend_object_store_get_object(*object TSRMLS_CC);
 
     entry_obj->entry = entry;
     oid = git_tree_entry_id(entry);
@@ -269,6 +277,8 @@ PHP_METHOD(git_repository, getCommit)
     char *hash;
     int hash_len = 0;
     int ret = 0;
+	php_git_repository_t *myobj;
+	php_git_commit_t *cobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &hash, &hash_len) == FAILURE){
@@ -277,7 +287,7 @@ PHP_METHOD(git_repository, getCommit)
     
     git_oid_mkstr(&oid, hash);
     
-    php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC);
+    myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC);
     repository = myobj->repository;
     odb = git_repository_database(repository);
     
@@ -297,7 +307,7 @@ PHP_METHOD(git_repository, getCommit)
             MAKE_STD_ZVAL(git_commit_object);
             object_init_ex(git_commit_object,git_commit_class_entry);
 
-            php_git_commit_t *cobj = (php_git_commit_t *) zend_object_store_get_object(git_commit_object TSRMLS_CC);
+            cobj = (php_git_commit_t *) zend_object_store_get_object(git_commit_object TSRMLS_CC);
             cobj->object = commit;
 
             add_property_zval(git_commit_object,"author", author);
@@ -321,13 +331,14 @@ PHP_METHOD(git_repository, __construct)
     int arg_len = 0;
     git_repository *repository;
     zval *object = getThis();
+	php_git_repository_t *myobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "|s", &repository_path, &arg_len) == FAILURE){
         return;
     }
 
-    php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC);
+    myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC);
 
     if(arg_len > 0){
         ret = git_repository_open(&repository,repository_path);
@@ -358,6 +369,8 @@ PHP_METHOD(git_repository, getTree)
     php_git_tree_entry_t *te;
     char buf[GIT_OID_HEXSZ+1] = {0};
     int i = 0;
+	php_git_repository_t *myobj;
+	php_git_tree_t *tobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &hash, &hash_len) == FAILURE){
@@ -365,7 +378,7 @@ PHP_METHOD(git_repository, getTree)
     }
 
     git_oid_mkstr(&oid, hash);
-    php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC);
+    myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC);
 
     ret = git_tree_lookup(&tree, myobj->repository, &oid);
     if(ret != GIT_SUCCESS){
@@ -377,7 +390,7 @@ PHP_METHOD(git_repository, getTree)
     MAKE_STD_ZVAL(git_tree);
     object_init_ex(git_tree, git_tree_class_entry);
 
-    php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC);
+    tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC);
     tobj->object = tree;
 
     RETURN_ZVAL(git_tree,0,0);
@@ -389,13 +402,14 @@ PHP_METHOD(git_repository, getWalker)
     zval *walker_object;
     git_revwalk *walk;
     int ret = 0;
+	php_git_walker_t *wobj;
 
     php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     ret = git_revwalk_new(&walk,myobj->repository);
 
     MAKE_STD_ZVAL(walker_object);
     object_init_ex(walker_object, git_walker_class_entry);
-    php_git_walker_t *wobj = (php_git_walker_t *) zend_object_store_get_object(walker_object TSRMLS_CC);
+    wobj = (php_git_walker_t *) zend_object_store_get_object(walker_object TSRMLS_CC);
     wobj->walker = walk;
 
     RETURN_ZVAL(walker_object,0,0);
@@ -409,6 +423,7 @@ PHP_METHOD(git_repository, addAlternate)
     git_odb *odb;
     git_odb_backend *odb_backend;
     int priority = 0;
+	int ret;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &backend, &priority) == FAILURE){
         return;
@@ -421,7 +436,7 @@ PHP_METHOD(git_repository, addAlternate)
     }
 
     odb = git_repository_database(this->repository);
-    int ret = php_git_odb_add_alternate(&odb, backend, priority);
+    ret = php_git_odb_add_alternate(&odb, backend, priority);
 }
 
 
@@ -432,6 +447,7 @@ PHP_METHOD(git_repository, addBackend)
     git_odb *odb;
     git_odb_backend *odb_backend;
     int priority = 0;
+	int ret;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &backend, &priority) == FAILURE){
         return;
@@ -443,7 +459,7 @@ PHP_METHOD(git_repository, addBackend)
     }
     
     odb = git_repository_database(this->repository);
-    int ret = php_git_odb_add_backend(&odb, backend, priority);
+    ret = php_git_odb_add_backend(&odb, backend, priority);
 }
 
 
@@ -458,6 +474,8 @@ PHP_METHOD(git_repository, lookupRef)
     git_oid *oid;
     git_rtype type;
     git_reference *reference;
+	php_git_reference_t *refobj;
+	int rr;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &name, &name_len) == FAILURE){
@@ -473,7 +491,7 @@ PHP_METHOD(git_repository, lookupRef)
 
     MAKE_STD_ZVAL(ref);
     object_init_ex(ref, git_reference_class_entry);
-    php_git_reference_t *refobj  = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
+    refobj = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
     refobj->object = reference;
 
     add_property_string_ex(ref,"name",  sizeof("name"),  (char *)git_reference_name(reference), 1 TSRMLS_CC);
@@ -484,7 +502,7 @@ PHP_METHOD(git_repository, lookupRef)
         if(target != NULL) {
             add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC);
         }
-        int rr = git_reference_resolve(&refobj->object,reference);
+        rr = git_reference_resolve(&refobj->object,reference);
         if(rr != GIT_SUCCESS){
             zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
                 "something wrong");
@@ -515,6 +533,8 @@ PHP_METHOD(git_repository, getReferences)
     array_init(references);
     for(i = 0; i < list->count; i++){
         zval *ref;
+		php_git_reference_t *refobj;
+		int rr;
 
         // FIXME
         result = git_reference_lookup(&reference, this->repository, list->strings[i]);
@@ -526,7 +546,7 @@ PHP_METHOD(git_repository, getReferences)
 
         MAKE_STD_ZVAL(ref);
         object_init_ex(ref, git_reference_class_entry);
-        php_git_reference_t *refobj  = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
+        refobj  = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC);
         refobj->object = reference;
 
         add_property_string_ex(ref,"name",  sizeof("name"),  (char *)git_reference_name(reference), 1 TSRMLS_CC);
@@ -537,7 +557,7 @@ PHP_METHOD(git_repository, getReferences)
             if(target != NULL) {
                 add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC);
             }
-            int rr = git_reference_resolve(&refobj->object,reference);
+            rr = git_reference_resolve(&refobj->object,reference);
             if(rr != GIT_SUCCESS){
                 zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
                     "something wrong");
@@ -607,6 +627,7 @@ PHP_METHOD(git_repository, open2)
     int git_index_file_len = 0;
     int git_work_tree_len = 0;
     git_repository *repository;
+	int ret;
     
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "ssss", &git_dir, &git_dir_len, &git_object_directory, &git_object_directory_len, &git_index_file, &git_index_file_len, &git_work_tree, &git_work_tree_len) == FAILURE){
@@ -618,7 +639,7 @@ PHP_METHOD(git_repository, open2)
         return;
     }
     
-    int ret = git_repository_open2(&repository,git_dir, git_object_directory, git_index_file, git_work_tree);
+    ret = git_repository_open2(&repository,git_dir, git_object_directory, git_index_file, git_work_tree);
     if(ret != GIT_SUCCESS){
         zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"can't open specified directories");
         RETURN_FALSE;
@@ -630,7 +651,7 @@ PHP_METHOD(git_repository, open2)
 }
 
 
-PHPAPI function_entry php_git_repository_methods[] = {
+static zend_function_entry php_git_repository_methods[] = {
     PHP_ME(git_repository, __construct,   arginfo_git_construct,      ZEND_ACC_PUBLIC)
     PHP_ME(git_repository, getCommit,     arginfo_git_get_commit,     ZEND_ACC_PUBLIC)
     PHP_ME(git_repository, getObject,     arginfo_git_get_object,     ZEND_ACC_PUBLIC)
diff --git a/src/signature.c b/src/signature.c
index 26037f662a..4be31798af 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -29,7 +29,7 @@
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_signature_class_entry;
+zend_class_entry *git_signature_class_entry;
 
 void create_signature_from_commit(zval **signature, git_signature *sig);
 static void php_git_signature_free_storage(php_git_signature_t *obj TSRMLS_DC);
@@ -49,7 +49,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature__construct, 0, 0, 3)
     ZEND_ARG_INFO(0, when)
 ZEND_END_ARG_INFO()
 
-PHPAPI function_entry php_git_signature_methods[] = {
+static zend_function_entry php_git_signature_methods[] = {
     PHP_ME(git_signature, __construct, arginfo_git_signature__construct, ZEND_ACC_PUBLIC)
     {NULL, NULL, NULL}
 };
@@ -61,6 +61,7 @@ PHP_METHOD(git_signature, __construct)
     int name_len  = 0;
     int email_len = 0;
     zval *time;
+	int ret;
     
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "ssz", &name, &name_len, &email, &email_len, &time) == FAILURE){
@@ -72,7 +73,7 @@ PHP_METHOD(git_signature, __construct)
         return;
     }
 
-    int ret = php_git_signature_create(getThis(), name, name_len, email, email_len, time);
+    ret = php_git_signature_create(getThis(), name, name_len, email, email_len, time);
     if (ret != GIT_SUCCESS) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Git\\Signature internal error");
     }
@@ -95,20 +96,22 @@ void create_signature_from_commit(zval **signature, git_signature *sig)
 {
     TSRMLS_FETCH();
     zval *datetime;
+	php_git_signature_t *object;
+	zval constructor;
+    zval method;
+    zval result;
+    zval *params[1];
+	
     MAKE_STD_ZVAL(*signature);
 
     object_init_ex(*signature,git_signature_class_entry);
-    php_git_signature_t *object = (php_git_signature_t *) zend_object_store_get_object(*signature TSRMLS_CC);
+    object = (php_git_signature_t *) zend_object_store_get_object(*signature TSRMLS_CC);
     object->signature = sig;
     
     add_property_string_ex(*signature,"name",sizeof("name"), sig->name,1 TSRMLS_CC);
     add_property_string_ex(*signature,"email",sizeof("email"),sig->email,1 TSRMLS_CC);
 
-    MAKE_STD_ZVAL(datetime);
-    zval constructor;
-    zval method;
-    zval result;
-    zval *params[1];
+    MAKE_STD_ZVAL(datetime);    
     ZVAL_STRING(&constructor,"__construct",0);
     ZVAL_STRING(&method,"setTimestamp", 0);
 
diff --git a/src/tag.c b/src/tag.c
index 6a3f5fa77b..eb71d8fd07 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -28,7 +28,7 @@
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_tag_class_entry;
+zend_class_entry *git_tag_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag__construct, 0, 0, 1)
     ZEND_ARG_INFO(0, repository)
@@ -60,20 +60,20 @@ static void php_git_tag_free_storage(php_git_tag_t *obj TSRMLS_DC)
 
 zend_object_value php_git_tag_new(zend_class_entry *ce TSRMLS_DC)
 {
-	zend_object_value retval;
-	php_git_tag_t *obj;
-	zval *tmp;
+    zend_object_value retval;
+    php_git_tag_t *obj;
+    zval *tmp;
 
-	obj = ecalloc(1, sizeof(*obj));
-	zend_object_std_init( &obj->zo, ce TSRMLS_CC );
-	zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+    obj = ecalloc(1, sizeof(*obj));
+    zend_object_std_init( &obj->zo, ce TSRMLS_CC );
+    zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
 
-	retval.handle = zend_objects_store_put(obj, 
+    retval.handle = zend_objects_store_put(obj, 
         (zend_objects_store_dtor_t)zend_objects_destroy_object,
         (zend_objects_free_object_storage_t)php_git_tag_free_storage,
         NULL TSRMLS_CC);
-	retval.handlers = zend_get_std_object_handlers();
-	return retval;
+    retval.handlers = zend_get_std_object_handlers();
+    return retval;
 }
 
 PHP_METHOD(git_tag, getMessage)
@@ -95,7 +95,7 @@ PHP_METHOD(git_tag, getTarget)
     php_git_tag_t *tag = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     const git_object *object;
     git_otype type;
-    
+
     object = git_tag_target(tag->object);
     type = git_object_type(object);
 */
@@ -105,6 +105,7 @@ PHP_METHOD(git_tag, setTarget)
 {
     php_git_tag_t *this = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     zval *target;
+    php_git_object_t *obj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "z", &target) == FAILURE){
@@ -116,8 +117,8 @@ PHP_METHOD(git_tag, setTarget)
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Git\\Tag::setTarget only allow Git\\Object.");
         return;
     }
-    php_git_object_t *obj = (php_git_object_t *) zend_object_store_get_object(target TSRMLS_CC);
-    
+    obj = (php_git_object_t *) zend_object_store_get_object(target TSRMLS_CC);
+
     git_tag_set_target(this->object, obj->object);
 }
 
@@ -142,7 +143,7 @@ PHP_METHOD(git_tag, setName)
     php_git_tag_t *this = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     char *name;
     int name_len = 0;
-    
+
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &name, &name_len) == FAILURE){
         return;
@@ -159,7 +160,8 @@ PHP_METHOD(git_tag, __construct)
     php_git_tag_t *this = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     php_git_repository_t *r_obj;
     zval *repository;
-    
+    int ret;
+
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "z", &repository) == FAILURE){
         return;
@@ -173,7 +175,7 @@ PHP_METHOD(git_tag, __construct)
     }
     r_obj = (php_git_repository_t *) zend_object_store_get_object(repository TSRMLS_CC);
 
-    int ret = git_tag_new(&this->object,r_obj->repository);
+    ret = git_tag_new(&this->object,r_obj->repository);
 
     if(ret != GIT_SUCCESS){
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "can't create Git\\Tag.");
@@ -181,7 +183,7 @@ PHP_METHOD(git_tag, __construct)
 }
 
 
-PHPAPI function_entry php_git_tag_methods[] = {
+static zend_function_entry php_git_tag_methods[] = {
     PHP_ME(git_tag, __construct, arginfo_git_tag__construct, ZEND_ACC_PUBLIC)
     PHP_ME(git_tag, getMessage,  NULL,                       ZEND_ACC_PUBLIC)
     PHP_ME(git_tag, getName,     NULL,                       ZEND_ACC_PUBLIC)
diff --git a/src/tree.c b/src/tree.c
index 4b51f04d27..9d3c7bcc68 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -25,10 +25,11 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_tree_class_entry;
+zend_class_entry *git_tree_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree__construct, 0, 0, 1)
     ZEND_ARG_INFO(0, repository)
@@ -95,6 +96,7 @@ PHP_METHOD(git_tree, path)
     git_tree_entry *entry;
     int ret = 0;
     git_object *object;
+	git_otype type;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &path, &path_len) == FAILURE){
@@ -111,7 +113,7 @@ PHP_METHOD(git_tree, path)
             zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"something uncaught error happend.");
             RETURN_FALSE;
         }
-        git_otype type = git_object_type(object);
+        type = git_object_type(object);
 
         if(type == GIT_OBJ_TREE) {
             // Todo: refactoring below block
@@ -120,15 +122,18 @@ PHP_METHOD(git_tree, path)
             zval *git_tree;
             zval *entries;
             zval *entry;
+			php_git_tree_t *tobj;
+			int r;
+			int i;
 
             MAKE_STD_ZVAL(git_tree);
             MAKE_STD_ZVAL(entries);
             array_init(entries);
             object_init_ex(git_tree, git_tree_class_entry);
-            php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC);
+            tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC);
             tobj->object = tree;
-            int r = git_tree_entrycount(tree);
-            int i = 0;
+            r = git_tree_entrycount(tree);
+            i = 0;
             for(i; i < r; i++){
                 create_tree_entry_from_entry(&entry,git_tree_entry_byindex(tree,i));
                 add_next_index_zval(entries, entry);
@@ -139,9 +144,11 @@ PHP_METHOD(git_tree, path)
         }else if(type == GIT_OBJ_BLOB){
             // Todo: refactoring below block
             zval *git_object;
+			php_git_blob_t *blobobj;
+			
             MAKE_STD_ZVAL(git_object);
             object_init_ex(git_object, git_blob_class_entry);
-            php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_object TSRMLS_CC);
+            blobobj = (php_git_blob_t *) zend_object_store_get_object(git_object TSRMLS_CC);
             blobobj->object = (git_blob *)object;
 
             add_property_stringl_ex(git_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC);
@@ -163,9 +170,12 @@ PHP_METHOD(git_tree, add)
     int entry_oid_len;
     int filename_len = 0;
     int attr = 0;
+	int ret;
 
     git_oid oid;
     git_tree *tree;
+	
+	php_git_tree_t *myobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "ssl", &entry_oid, &entry_oid_len,&filename,&filename_len,&attr) == FAILURE){
@@ -173,8 +183,8 @@ PHP_METHOD(git_tree, add)
     }
 
     git_oid_mkstr(&oid, entry_oid);
-    php_git_tree_t *myobj = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
-    int ret = git_tree_add_entry(&entry, myobj->object, &oid, filename, attr);
+    myobj = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+    ret = git_tree_add_entry(&entry, myobj->object, &oid, filename, attr);
     if(ret != GIT_SUCCESS) {
         php_error_docref(NULL TSRMLS_CC, E_ERROR, "can't add tree entry");
         RETURN_FALSE;
@@ -186,16 +196,19 @@ PHP_METHOD(git_tree, add)
 PHP_METHOD(git_tree, __construct)
 {
     zval *z_repository;
+	php_git_repository_t *git;
+	php_git_tree_t *obj;
+	int ret;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "z", &z_repository) == FAILURE){
         return;
     }
 
-    php_git_repository_t *git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC);
-    php_git_tree_t *obj = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+    git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC);
+    obj = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     
-    int ret = git_tree_new(&obj->object,git->repository);
+    ret = git_tree_new(&obj->object,git->repository);
 
     if(ret != GIT_SUCCESS){
         php_error_docref(NULL TSRMLS_CC, E_ERROR, "can't create new tree");
@@ -207,10 +220,11 @@ PHP_METHOD(git_tree, getIterator)
 {
     php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     zval *iterator;
+	php_git_tree_iterator_t *obj;
     
     MAKE_STD_ZVAL(iterator);
     object_init_ex(iterator,git_tree_iterator_class_entry);
-    php_git_tree_iterator_t *obj = (php_git_tree_iterator_t *) zend_object_store_get_object(iterator TSRMLS_CC);
+    obj = (php_git_tree_iterator_t *) zend_object_store_get_object(iterator TSRMLS_CC);
     obj->tree = this->object;
     obj->offset = 0;
     RETURN_ZVAL(iterator,0,0);
@@ -238,20 +252,22 @@ PHP_METHOD(git_tree, remove)
     php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     char *path;
     int path_len = 0;
+	git_tree_entry *entry;
+	int result;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &path, &path_len) == FAILURE){
         return;
     }
 
-    git_tree_entry *entry = git_tree_entry_byname(this->object,path);
+    entry = git_tree_entry_byname(this->object,path);
     if(entry == NULL){
         zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
             "specified path does not exist.");
         RETURN_FALSE;
     }
 
-    int result = git_tree_remove_entry_byname(this->object, path);
+    result = git_tree_remove_entry_byname(this->object, path);
     if(result != GIT_SUCCESS){
         zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
             "can't remove tree entry");
@@ -268,9 +284,9 @@ PHP_METHOD(git_tree, getEntries)
     
     int r = git_tree_entrycount(this->object);
     zval *entries;
-    MAKE_STD_ZVAL(entries);
-    array_init(entries);
-    zval *array_ptr;
+	zval *array_ptr;
+    MAKE_STD_ZVAL(entries);	
+    array_init(entries);    
     for(i = 0; i < r; i++){
         create_tree_entry_from_entry(&array_ptr, git_tree_entry_byindex(this->object,i));
         add_next_index_zval(entries,  array_ptr);
@@ -280,7 +296,7 @@ PHP_METHOD(git_tree, getEntries)
 }
 
 
-PHPAPI function_entry php_git_tree_methods[] = {
+static zend_function_entry php_git_tree_methods[] = {
     PHP_ME(git_tree, __construct, arginfo_git_tree__construct, ZEND_ACC_PUBLIC)
     PHP_ME(git_tree, getEntry,    arginfo_git_tree_get_entry,  ZEND_ACC_PUBLIC)
     PHP_ME(git_tree, getEntries,  NULL,                        ZEND_ACC_PUBLIC)
diff --git a/src/tree_entry.c b/src/tree_entry.c
index c50fb5336e..6a86a42a44 100644
--- a/src/tree_entry.c
+++ b/src/tree_entry.c
@@ -25,10 +25,11 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_tree_entry_class_entry;
+zend_class_entry *git_tree_entry_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_set_id, 0, 0, 1)
     ZEND_ARG_INFO(0, hash)
@@ -68,6 +69,7 @@ PHP_METHOD(git_tree_entry, setId)
     git_oid oid;
     
     int ret = 0;
+	char out[GIT_OID_HEXSZ+1] = {0};
     
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &hash, &hash_len) == FAILURE){
@@ -76,7 +78,6 @@ PHP_METHOD(git_tree_entry, setId)
     git_oid_mkstr(&oid,hash);
     git_tree_entry_set_id(this->entry,&oid);
 
-    char out[GIT_OID_HEXSZ+1] = {0};
     git_oid_to_string(out,GIT_OID_HEXSZ+1,git_tree_entry_id(this->entry));
     
     add_property_string(getThis(), "oid", hash, 1);
@@ -96,36 +97,40 @@ PHP_METHOD(git_tree_entry, toObject)
     if(ret == GIT_SUCCESS){
         type = git_object_type(object);
         if (type == GIT_OBJ_BLOB) {
-
+            php_git_blob_t *blobobj;
             zval *git_raw_object;
             MAKE_STD_ZVAL(git_raw_object);
             object_init_ex(git_raw_object, git_blob_class_entry);
-            php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_raw_object TSRMLS_CC);
+            blobobj = (php_git_blob_t *) zend_object_store_get_object(git_raw_object TSRMLS_CC);
             blobobj->object = (git_blob *)object;
 
             add_property_stringl_ex(git_raw_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC);
             RETURN_ZVAL(git_raw_object,0,0);
         } else if(type == GIT_OBJ_TREE) {
             git_tree *tree = (git_tree *)object;
+			int r;
+			int i;
+			char buf[GIT_OID_HEXSZ+1] = {0};
+            char *offset;
+            git_oid *moid;
+            zval *array_ptr;
             zval *git_tree;
             zval *entries;
+			php_git_tree_t *tobj;
+			
             MAKE_STD_ZVAL(git_tree);
             MAKE_STD_ZVAL(entries);
             array_init(entries);
             object_init_ex(git_tree, git_tree_class_entry);
 
-            int r = git_tree_entrycount(tree);
-            int i = 0;
-            char buf[GIT_OID_HEXSZ+1] = {0};
-            char *offset;
-            git_oid *moid;
-            zval *array_ptr;
+            r = git_tree_entrycount(tree);
+            i = 0;           
 
             for(i; i < r; i++){
                 create_tree_entry_from_entry(&array_ptr, git_tree_entry_byindex(tree,i));
                 add_next_index_zval(entries,  array_ptr);
             }
-            php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC);
+            tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC);
             tobj->object = tree;
             add_property_zval(git_tree,"entries", entries);
             RETURN_ZVAL(git_tree,0,0);
@@ -167,7 +172,7 @@ PHP_METHOD(git_tree_entry, isBlob)
 
 
 
-PHPAPI function_entry php_git_tree_entry_methods[] = {
+static zend_function_entry php_git_tree_entry_methods[] = {
     PHP_ME(git_tree_entry, __construct, NULL, ZEND_ACC_PRIVATE)
     PHP_ME(git_tree_entry, setId,    arginfo_git_tree_entry_set_id, ZEND_ACC_PUBLIC)
     PHP_ME(git_tree_entry, toObject, NULL,                          ZEND_ACC_PUBLIC)
diff --git a/src/tree_iterator.c b/src/tree_iterator.c
index 287a2aa978..40c2c71f0e 100644
--- a/src/tree_iterator.c
+++ b/src/tree_iterator.c
@@ -25,12 +25,13 @@
 #include "php_git.h"
 #include <spl/spl_array.h>
 #include <zend_interfaces.h>
+#include <zend_exceptions.h>
 #include <string.h>
 #include <time.h>
 
 extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry);
 
-PHPAPI zend_class_entry *git_tree_iterator_class_entry;
+zend_class_entry *git_tree_iterator_class_entry;
 extern void php_tree_index_entry_create(zval **index, git_tree_entry *entry);
 
 static void php_git_tree_iterator_free_storage(php_git_tree_iterator_t *obj TSRMLS_DC)
@@ -113,19 +114,20 @@ PHP_METHOD(git_tree_iterator, __construct)
 {
     php_git_tree_iterator_t *this = (php_git_tree_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     zval *php_tree_index;
+	php_git_tree_t *tree;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "z", &php_tree_index) == FAILURE){
         return;
     }
-    php_git_tree_t *tree = (php_git_tree_t *) zend_object_store_get_object(php_tree_index TSRMLS_CC);
+    tree = (php_git_tree_t *) zend_object_store_get_object(php_tree_index TSRMLS_CC);
 
     this->tree = tree->object;
     this->offset = 0;
 }
 
 
-PHPAPI function_entry php_git_tree_iterator_methods[] = {
+static zend_function_entry php_git_tree_iterator_methods[] = {
     PHP_ME(git_tree_iterator, __construct, arginfo_git_tree_iterator__construct,ZEND_ACC_PUBLIC)
     PHP_ME(git_tree_iterator, current,     NULL,                        ZEND_ACC_PUBLIC)
     PHP_ME(git_tree_iterator, key,         NULL,                        ZEND_ACC_PUBLIC)
diff --git a/src/walker.c b/src/walker.c
index fe020deb77..c4af3f5d7f 100644
--- a/src/walker.c
+++ b/src/walker.c
@@ -28,7 +28,7 @@
 #include <string.h>
 #include <time.h>
 
-PHPAPI zend_class_entry *git_walker_class_entry;
+zend_class_entry *git_walker_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_git_walker_hide, 0, 0, 1)
     ZEND_ARG_INFO(0, hash)
@@ -82,13 +82,14 @@ PHP_METHOD(git_walker, hide)
     git_commit *commit;
     git_repository *repository;
     git_oid oid;
+	php_git_walker_t *myobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &hash, &hash_len) == FAILURE){
         return;
     }
 
-    php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+    myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     walker = myobj->walker;
 
     repository = git_revwalk_repository(walker);
@@ -106,13 +107,14 @@ PHP_METHOD(git_walker, push)
     git_commit *head;
     git_revwalk *walker;
     git_repository *repository;
+	php_git_walker_t *myobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "s", &hash, &hash_len) == FAILURE){
         return;
     }
 
-    php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+    myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     walker = myobj->walker;
     repository = git_revwalk_repository(walker);
     
@@ -130,21 +132,22 @@ PHP_METHOD(git_walker, next)
     git_commit *commit;
     git_revwalk *walker;
     git_signature *signature;
+	int ret;
+	zval *author;
+    zval *committer;
+	php_git_commit_t *cobj;
 
     php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     walker = myobj->walker;
 
-    int ret = git_revwalk_next(&oid,walker);
+    ret = git_revwalk_next(&oid,walker);
     if(ret != GIT_SUCCESS){
         RETURN_FALSE;
     }
     git_object_lookup((git_object **)&commit, git_revwalk_repository(walker), &oid, GIT_OBJ_COMMIT);
 
     MAKE_STD_ZVAL(git_commit_object);
-    object_init_ex(git_commit_object,git_commit_class_entry);
-
-    zval *author;
-    zval *committer;
+    object_init_ex(git_commit_object,git_commit_class_entry);    
 
     create_signature_from_commit(&author, git_commit_author(commit));
     create_signature_from_commit(&committer, git_commit_committer(commit));
@@ -152,7 +155,7 @@ PHP_METHOD(git_walker, next)
     MAKE_STD_ZVAL(git_commit_object);
     object_init_ex(git_commit_object,git_commit_class_entry);
 
-    php_git_commit_t *cobj = (php_git_commit_t *) zend_object_store_get_object(git_commit_object TSRMLS_CC);
+    cobj = (php_git_commit_t *) zend_object_store_get_object(git_commit_object TSRMLS_CC);
     cobj->object = commit;
 
     add_property_zval(git_commit_object,"author", author);
@@ -172,18 +175,19 @@ PHP_METHOD(git_walker, reset)
 PHP_METHOD(git_walker, sort)
 {
     int mode = 0;
+	php_git_walker_t *myobj;
 
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
         "l", &mode) == FAILURE){
         return;
     }
 
-    php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
+    myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
     git_revwalk_sorting(myobj->walker, mode);
     RETURN_TRUE;
 }
 
-PHPAPI function_entry php_git_walker_methods[] = {
+static zend_function_entry php_git_walker_methods[] = {
     PHP_ME(git_walker, __construct, NULL,                    ZEND_ACC_PUBLIC)
     PHP_ME(git_walker, push,        arginfo_git_walker_push, ZEND_ACC_PUBLIC)
     PHP_ME(git_walker, next,        NULL,                    ZEND_ACC_PUBLIC)