diff --git a/CMakeLists.txt b/CMakeLists.txt
index b59e18f2718cafca285479b9d8bcfc140d79773c..8af021546d018e2256f81d45aea5172c43f74fd3 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,7 +21,6 @@ set(DAP_CHAIN_CRYPTO_HEADERS
         dap_chain_sign.h
         dap_chain_cert.h
         dap_chain_cert_file.h
-
     )
 
 if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
@@ -37,7 +36,6 @@ add_subdirectory(monero_crypto)
 include_directories("${monero_crypto_INCLUDE_DIRS}")
 add_definitions ("${monero_crypto_DEFINITIONS}")
 
-
 add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_CRYPTO_SRCS} ${DAP_CHAIN_CRYPTO_HEADERS})
 
 target_include_directories(dap_chain_crypto INTERFACE .)
diff --git a/dap_chain_cert.c b/dap_chain_cert.c
index d98289a13653d9f6ee53e27907dc0b1b8355d37b..c4baf6a6ddcf787ac5b690976a8fbc135d186133 100755
--- a/dap_chain_cert.c
+++ b/dap_chain_cert.c
@@ -292,10 +292,10 @@ dap_chain_cert_t * dap_chain_cert_new(const char * a_name)
 {
     dap_chain_cert_t * l_ret = DAP_NEW_Z(dap_chain_cert_t);
     l_ret->_pvt = DAP_NEW_Z(dap_chain_cert_pvt_t);
-    snprintf(l_ret->name,sizeof(l_ret->name),"%s",a_name);
+    dap_snprintf(l_ret->name,sizeof(l_ret->name),"%s",a_name);
 
     dap_chain_cert_item_t * l_cert_item = DAP_NEW_Z(dap_chain_cert_item_t);
-    snprintf(l_cert_item->name,sizeof(l_cert_item->name),"%s",a_name);
+    dap_snprintf(l_cert_item->name,sizeof(l_cert_item->name),"%s",a_name);
     l_cert_item->cert = l_ret;
     HASH_ADD_STR(s_certs,name,l_cert_item);
 
@@ -334,7 +334,7 @@ dap_chain_cert_t * dap_chain_cert_add_file(const char * a_cert_name,const char *
 {
     size_t l_cert_path_length = strlen(a_cert_name)+8+strlen(a_folder_path);
     char * l_cert_path = DAP_NEW_Z_SIZE(char,l_cert_path_length);
-    snprintf(l_cert_path,l_cert_path_length,"%s/%s.dcert",a_folder_path,a_cert_name);
+    dap_snprintf(l_cert_path,l_cert_path_length,"%s/%s.dcert",a_folder_path,a_cert_name);
     if( access( l_cert_path, F_OK ) == -1 ) {
         log_it (L_ERROR, "File %s is not exists! ", l_cert_path);
         exit(-701);
@@ -358,7 +358,7 @@ int dap_chain_cert_save_to_folder(dap_chain_cert_t * a_cert, const char *a_file_
     const char * l_cert_name = a_cert->name;
     size_t l_cert_path_length = strlen(l_cert_name)+8+strlen(a_file_dir_path);
     char * l_cert_path = DAP_NEW_Z_SIZE(char,l_cert_path_length);
-    snprintf(l_cert_path,l_cert_path_length,"%s/%s.dcert",a_file_dir_path,l_cert_name);
+    dap_snprintf(l_cert_path,l_cert_path_length,"%s/%s.dcert",a_file_dir_path,l_cert_name);
     ret = dap_chain_cert_file_save(a_cert,l_cert_path);
     DAP_DELETE( l_cert_path);
     return ret;
diff --git a/dap_chain_cert_file.c b/dap_chain_cert_file.c
index 6937ae3ebede1d0ea46868a1b74fb8dfd74eaa6a..50e51c1b605368225bdb895ddead5e672c0356f9 100755
--- a/dap_chain_cert_file.c
+++ b/dap_chain_cert_file.c
@@ -40,7 +40,7 @@
  */
 int dap_chain_cert_file_save(dap_chain_cert_t * a_cert, const char * a_cert_file_path)
 {
-    FILE * l_file = fopen(a_cert_file_path,"w");
+    FILE * l_file = fopen(a_cert_file_path,"wb");
     if( l_file ){
         uint32_t l_data_size = 0;
         void * l_data = dap_chain_cert_mem_save(a_cert, &l_data_size);
@@ -150,7 +150,7 @@ lb_exit:
 dap_chain_cert_t* dap_chain_cert_file_load(const char * a_cert_file_path)
 {
     dap_chain_cert_t * l_ret = NULL;
-    FILE * l_file = fopen(a_cert_file_path,"r");
+    FILE * l_file = fopen(a_cert_file_path,"rb");
 
     if( l_file ){
         fseek(l_file, 0L, SEEK_END);
diff --git a/dap_hash.h b/dap_hash.h
index 392a26c9040a5c465caf5c7338d4cbc7e2adf324..fd72c9494fa8a88a31bd9933f7e2bc13f9860983 100755
--- a/dap_hash.h
+++ b/dap_hash.h
@@ -35,7 +35,6 @@ typedef enum dap_hash_type {
     DAP_HASH_TYPE_SLOW_0 = 1,
 } dap_hash_type_t;
 
-
 static inline void dap_hash(const void * a_data_in, size_t a_data_in_size,
                      void * a_data_out, size_t a_data_out_size,
                      dap_hash_type_t a_type ){
diff --git a/dap_hash_keccak.h b/dap_hash_keccak.h
index 29a4830f1008b5954bdd4fe66fd2e0c6548a77a6..1dfcec53f67b9e71202524a08fb708708dc8bd56 100755
--- a/dap_hash_keccak.h
+++ b/dap_hash_keccak.h
@@ -25,7 +25,6 @@
 #pragma once
 #include "keccak.h"
 
-
 static inline void dap_hash_keccak(const void * a_in, size_t a_in_size, void * a_out, size_t a_out_size)
 {
     keccak((const uint8_t*) a_in, a_in_size, (uint8_t *) a_out,(int)  a_out_size );
diff --git a/monero_crypto/tree-hash.c b/monero_crypto/tree-hash.c
index eb98c31b78924245c64c73ff0cf6be64f4b17585..cabb3d2224c3f8851e73c8c635af02cbc866988a 100755
--- a/monero_crypto/tree-hash.c
+++ b/monero_crypto/tree-hash.c
@@ -34,7 +34,7 @@
 
 #include "hash-ops.h"
 
-#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__)
+#if !defined(_WIN32) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__)
  #include <alloca.h>
 #else
  #include <stdlib.h>
@@ -44,24 +44,24 @@
 * Round to power of two, for count>=3 and for count being not too large (as reasonable for tree hash calculations)
 */
 size_t tree_hash_cnt(size_t count) {
-	// This algo has some bad history but all we are doing is 1 << floor(log2(count))
-	// There are _many_ ways to do log2, for some reason the one selected was the most obscure one,
-	// and fixing it made it even more obscure.
-	//
-	// Iterative method implemented below aims for clarity over speed, if performance is needed
-	// then my advice is to use the BSR instruction on x86
-	//
-	// All the paranoid asserts have been removed since it is trivial to mathematically prove that
-	// the return will always be a power of 2.
-	// Problem space has been defined as 3 <= count <= 2^28. Of course quarter of a billion transactions
-	// is not a sane upper limit for a block, so there will be tighter limits in other parts of the code
+  // This algo has some bad history but all we are doing is 1 << floor(log2(count))
+  // There are _many_ ways to do log2, for some reason the one selected was the most obscure one,
+  // and fixing it made it even more obscure.
+  //
+  // Iterative method implemented below aims for clarity over speed, if performance is needed
+  // then my advice is to use the BSR instruction on x86
+  //
+  // All the paranoid asserts have been removed since it is trivial to mathematically prove that
+  // the return will always be a power of 2.
+  // Problem space has been defined as 3 <= count <= 2^28. Of course quarter of a billion transactions
+  // is not a sane upper limit for a block, so there will be tighter limits in other parts of the code
 
-	assert( count >= 3 ); // cases for 0,1,2 are handled elsewhere
-	assert( count <= 0x10000000 ); // sanity limit to 2^28, MSB=1 will cause an inf loop
+  assert( count >= 3 ); // cases for 0,1,2 are handled elsewhere
+  assert( count <= 0x10000000 ); // sanity limit to 2^28, MSB=1 will cause an inf loop
 
-	size_t pow = 2;
-	while(pow < count) pow <<= 1;
-	return pow >> 1;
+  size_t pow = 2;
+  while(pow < count) pow <<= 1;
+  return pow >> 1;
 }
 
 void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash) {
@@ -90,7 +90,7 @@ void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash) {
 
     char (*ints)[HASH_SIZE];
     size_t ints_size = cnt * HASH_SIZE;
-    ints = alloca(ints_size); 	memset( ints , 0 , ints_size);  // allocate, and zero out as extra protection for using uninitialized mem
+    ints = alloca(ints_size);   memset( ints , 0 , ints_size);  // allocate, and zero out as extra protection for using uninitialized mem
 
     memcpy(ints, hashes, (2 * cnt - count) * HASH_SIZE);