diff --git a/CMakeLists.txt b/CMakeLists.txt
index d913c2051097a9d850d2af990306cacb3b34d6b1..c2e805e3ced57fafd25266c347da6a629b4340f1 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,7 +9,6 @@ if(WIN32)
   include_directories(../3rdparty/wepoll/include/)
   include_directories(../3rdparty/uthash/src/)
   include_directories(../3rdparty/libjson-c/)
-  include_directories(../3rdparty/libmagic/src/)
   include_directories(../3rdparty/curl/include/)
   include_directories(../3rdparty/libsqlite3/)
 endif()
diff --git a/dap_chain_global_db.c b/dap_chain_global_db.c
index 0d173f22c3ad69bf9cf0ab100017678f3c60612a..4f05745f3d07f16cd45f924c96d9472c362ebc0a 100755
--- a/dap_chain_global_db.c
+++ b/dap_chain_global_db.c
@@ -27,7 +27,7 @@
 #include <pthread.h>
 #include <time.h>
 #include <assert.h>
-#include <string.h>
+//#include <string.h>
 
 #include "uthash.h"
 
@@ -39,6 +39,7 @@
 
 #ifdef WIN32
 #include "registry.h"
+#include <string.h>
 #endif
 
 #ifndef MAX_PATH
diff --git a/dap_chain_global_db_driver.c b/dap_chain_global_db_driver.c
index 07d580d037c091db86a14e6941115c5f70127b8a..aa9dbecd62b43fa40cf1a62ce19bcaef972a6e32 100755
--- a/dap_chain_global_db_driver.c
+++ b/dap_chain_global_db_driver.c
@@ -27,6 +27,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <pthread.h>
+#include <assert.h>
 
 #include "dap_common.h"
 #include "dap_strfuncs.h"
diff --git a/dap_chain_global_db_driver_cdb.c b/dap_chain_global_db_driver_cdb.c
index f1250d7036543187ff56ca939608dfe5e21eb407..670ebe85434c448e3ab120c6d22af2a84c4719f4 100644
--- a/dap_chain_global_db_driver_cdb.c
+++ b/dap_chain_global_db_driver_cdb.c
@@ -151,10 +151,8 @@ pcdb_instance dap_cdb_init_group(char *a_group, int a_flags) {
     l_cdb_i = DAP_NEW(cdb_instance);
     l_cdb_i->local_group = dap_strdup(a_group);
     l_cdb_i->cdb = cdb_new();
-    memset(l_cdb_path, '\0', strlen(s_cdb_path) + strlen(a_group) + 2);
-    strcat(l_cdb_path, s_cdb_path);
-    strcat(l_cdb_path, "/");
-    strcat(l_cdb_path, a_group);
+    memset(l_cdb_path, '\0', sizeof(l_cdb_path));
+    dap_snprintf(l_cdb_path, sizeof(l_cdb_path), "%s/%s", s_cdb_path, a_group);
     cdb_options l_opts = { 1000000, 128, 1024 };
     if (cdb_option(l_cdb_i->cdb, l_opts.hsize, l_opts.pcacheMB, l_opts.rcacheMB) != CDB_SUCCESS) {
         log_it(L_ERROR, "Options are inacceptable: \"%s\"", cdb_errmsg(cdb_errno(l_cdb_i->cdb)));
@@ -245,70 +243,60 @@ pcdb_instance dap_cdb_get_db_by_group(const char *a_group) {
 }
 
 int dap_cdb_add_group(const char *a_group) {
-    char* l_cdb_path = malloc(strlen(s_cdb_path) + strlen(a_group) + 2);
-    memset(l_cdb_path, '\0', strlen(s_cdb_path) + strlen(a_group) + 2);
-    strcat(l_cdb_path, s_cdb_path);
-    strcat(l_cdb_path, "/");
-    strcat(l_cdb_path, a_group);
-
+    char l_cdb_path[strlen(s_cdb_path) + strlen(a_group) + 2];
+    memset(l_cdb_path, '\0', sizeof(l_cdb_path));
+    dap_snprintf(l_cdb_path, sizeof(l_cdb_path), "%s/%s", s_cdb_path, a_group);
 #ifdef _WIN32
     mkdir(l_cdb_path);
 #else
     mkdir(l_cdb_path, 0755);
 #endif
-
-    free(l_cdb_path);
     return 0;
 }
 
 int dap_db_driver_cdb_deinit() {
-    cdb_instance *cur_cdb, *tmp;
+    pcdb_instance cur_cdb, tmp;
+    pthread_mutex_lock(&cdb_mutex);
     HASH_ITER(hh, s_cdb, cur_cdb, tmp) {
         DAP_DELETE(cur_cdb->local_group);
         cdb_destroy(cur_cdb->cdb);
         HASH_DEL(s_cdb, cur_cdb);
         DAP_DELETE(cur_cdb);
     }
+    pthread_mutex_unlock(&cdb_mutex);
     if (s_cdb_path) {
         DAP_DELETE(s_cdb_path);
     }
     return CDB_SUCCESS;
 }
 
-int dap_db_driver_cdb_flush(void){
-    log_it(L_DEBUG, "Start flush cuttdb.");
-    //CLOSE
+int dap_db_driver_cdb_flush(void) {
+    int ret = 0;
+    log_it(L_INFO, "Flushing CDB to disk");
     cdb_instance *cur_cdb, *tmp;
+    pthread_mutex_lock(&cdb_mutex);
     HASH_ITER(hh, s_cdb, cur_cdb, tmp) {
-        DAP_DELETE(cur_cdb->local_group);
-        cdb_destroy(cur_cdb->cdb);
-        HASH_DEL(s_cdb, cur_cdb);
-        DAP_DELETE(cur_cdb);
-    }
-    //SYNC
-#ifndef _WIN32
-    sync();
-#endif
-    //OPEN
-    struct dirent *d;
-    DIR *dir = opendir(s_cdb_path);
-    if (!dir) {
-        log_it(L_ERROR, "Couldn't open db directory");
-        return -1;
-    }
-    for (d = readdir(dir); d; d = readdir(dir)) {
-        if (!dap_strcmp(d->d_name, ".") || !dap_strcmp(d->d_name, "..")) {
-            continue;
+        cdb_close(cur_cdb->cdb);
+        char l_cdb_path[strlen(s_cdb_path) + strlen(cur_cdb->local_group) + 2];
+        memset(l_cdb_path, '\0', sizeof(l_cdb_path));
+        dap_snprintf(l_cdb_path, sizeof(l_cdb_path), "%s/%s", s_cdb_path, cur_cdb->local_group);
+// Re-application of options might be required
+        cdb_options l_opts = { 1000000, 128, 1024 };
+        if (cdb_option(cur_cdb->cdb, l_opts.hsize, l_opts.pcacheMB, l_opts.rcacheMB) != CDB_SUCCESS) {
+            log_it(L_ERROR, "Options are inacceptable: \"%s\"", cdb_errmsg(cdb_errno(cur_cdb->cdb)));
+            ret = -1;
+            goto RET;
         }
-        pcdb_instance l_cdb_i = dap_cdb_init_group(d->d_name, CDB_CREAT | CDB_PAGEWARMUP);
-        if (!l_cdb_i) {
-            dap_db_driver_cdb_deinit();
-            closedir(dir);
-            return -2;
+        if(cdb_open(cur_cdb->cdb, l_cdb_path, CDB_CREAT | CDB_PAGEWARMUP) != CDB_SUCCESS) {
+            log_it(L_ERROR, "An error occured while opening CDB: \"%s\"", cdb_errmsg(cdb_errno(cur_cdb->cdb)));
+            ret = -2;
+            goto RET;
         }
     }
-    closedir(dir);
-    return 0;
+    log_it(L_INFO, "All data dumped");
+RET:
+    pthread_mutex_unlock(&cdb_mutex);
+    return ret;
 }
 
 dap_store_obj_t *dap_db_driver_cdb_read_last_store_obj(const char* a_group) {
diff --git a/dap_chain_global_db_driver_sqlite.c b/dap_chain_global_db_driver_sqlite.c
index 2495c4d9816c181c48ca8a0c5ee8c145bafe9d59..e79d6f49844cc679e314f42abc359305b675ddf7 100755
--- a/dap_chain_global_db_driver_sqlite.c
+++ b/dap_chain_global_db_driver_sqlite.c
@@ -1,29 +1,34 @@
 /*
  * Authors:
+ * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
  * Alexander Lysikov <alexander.lysikov@demlabs.net>
  * DeM Labs Inc.   https://demlabs.net
- * Kelvin Project https://github.com/kelvinblockchain
- * Copyright  (c) 2019
+ * CellFrame       https://cellframe.net
+ * Sources         https://gitlab.demlabs.net/cellframe
+ * Copyright  (c) 2017-2019
  * All rights reserved.
 
- This file is part of DAP (Deus Applications Prototypes) the open source project
+ This file is part of CellFrame SDK the open source project
 
- DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
+    CellFrame SDK is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
 
- DAP is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
+    CellFrame SDK is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
 
- You should have received a copy of the GNU General Public License
- along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
- */
+    You should have received a copy of the GNU General Public License
+    along with any CellFrame SDK based project.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
 #include <stddef.h>
 #include <string.h>
+#ifdef DAP_OS_UNIX
+#include <unistd.h>
+#endif
 #include "dap_common.h"
 #include "dap_hash.h"
 #include "dap_strfuncs.h"
diff --git a/dap_chain_global_db_driver_sqlite.h b/dap_chain_global_db_driver_sqlite.h
index 09342024f526d62398fb1ac361cc71673fa3b781..2818058580142410e898a2c35bac84c787151b28 100755
--- a/dap_chain_global_db_driver_sqlite.h
+++ b/dap_chain_global_db_driver_sqlite.h
@@ -1,26 +1,28 @@
 /*
  * Authors:
+ * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
  * Alexander Lysikov <alexander.lysikov@demlabs.net>
  * DeM Labs Inc.   https://demlabs.net
- * Kelvin Project https://github.com/kelvinblockchain
- * Copyright  (c) 2019
+ * CellFrame       https://cellframe.net
+ * Sources         https://gitlab.demlabs.net/cellframe
+ * Copyright  (c) 2017-2019
  * All rights reserved.
 
- This file is part of DAP (Deus Applications Prototypes) the open source project
+ This file is part of CellFrame SDK the open source project
 
- DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
+    CellFrame SDK is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
 
- DAP is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
+    CellFrame SDK is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
 
- You should have received a copy of the GNU General Public License
- along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
- */
+    You should have received a copy of the GNU General Public License
+    along with any CellFrame SDK based project.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
 #include "sqlite3.h"
 #include "dap_chain_global_db_driver.h"