diff --git a/stream/CMakeLists.txt b/stream/CMakeLists.txt
index 3e8300264671e8d04f1922151ddcdf2b713ef47e..65062f4f8b44f368b81114e4917345d813328add 100644
--- a/stream/CMakeLists.txt
+++ b/stream/CMakeLists.txt
@@ -7,20 +7,18 @@ include_directories("${INCLUDE_DIRECTORIES} ${dap_core_INCLUDE_DIRS}")
 include_directories("${INCLUDE_DIRECTORIES} ${dap_core_server_INCLUDE_DIRS}")
 include_directories("${INCLUDE_DIRECTORIES} ${dap_crypto_INCLUDE_DIRS}")
 include_directories("${INCLUDE_DIRECTORIES} ${dap_client_INCLUDE_DIRS}")
-include_directories("${INCLUDE_DIRECTORIES} ${dap_auth_INCLUDE_DIRS}")
 include_directories("${INCLUDE_DIRECTORIES} ${dap_session_INCLUDE_DIRS}")
-include_directories("${INCLUDE_DIRECTORIES} ${dap_db_INCLUDE_DIRS}")
 include_directories("${INCLUDE_DIRECTORIES} ${dap_http_INCLUDE_DIRS}")
 include_directories("${INCLUDE_DIRECTORIES} ${dap_http_server_INCLUDE_DIRS}")
+include_directories("${INCLUDE_DIRECTORIES} ${dap_enc_server_INCLUDE_DIRS}")
 include_directories("${INCLUDE_DIRECTORIES} ${MONGO_INCLUDE_DIRS}")
 
 add_definitions ("${dap_core_DEFINITIONS}")
 add_definitions ("${dap_core_server_DEFINITIONS}")
 add_definitions ("${dap_crypto_DEFINITIONS}")
 add_definitions ("${dap_client_DEFINITIONS}")
-add_definitions ("${dap_auth_DEFINITIONS}")
-add_definitions ("${dap_db_DEFINITIONS}")
 add_definitions ("${dap_http_server_DEFINITIONS}")
+add_definitions ("${dap_enc_server_DEFINITIONS}")
 add_definitions ("${dap_http_DEFINITIONS}")
 add_definitions ("${dap_session_DEFINITIONS}")
 
diff --git a/stream/stream.c b/stream/stream.c
index 48403f171cfb70d6008b28ae15ffc2d706de8c01..aabc3801fd31e53345d358e45be41b1c4ef3bca7 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -102,68 +102,55 @@ void stream_headers_read(dap_http_client_t * cl_ht, void * arg)
    // int raw_size;
     unsigned int id=0;
 
-    db_auth_info_t * ai = db_auth_info_by_cookie(cl_ht->in_cookie);
-
-    if (ai == NULL)
-        ai = db_search_cookie_in_db(cl_ht->in_cookie);
-
-    if(ai){
-        log_it(L_DEBUG,"Prepare data stream");
-        if(cl_ht->in_query_string[0]){
-            log_it(L_INFO,"Query string [%s]",cl_ht->in_query_string);
-            if(sscanf(cl_ht->in_query_string,"fj913htmdgaq-d9hf=%u",&id)==1){
-                stream_session_t * ss=NULL;
-                ss=stream_session_id(id);
-                if(ss==NULL){
-                    log_it(L_ERROR,"No session id %u was found",id);
-                    cl_ht->reply_status_code=404;
-                    strcpy(cl_ht->reply_reason_phrase,"Not found");
-                }else{
-                    log_it(L_INFO,"Session id %u was found with media_id = %d",id,ss->media_id);
-                    if(stream_session_open(ss)==0){ // Create new stream
-                        stream_t * sid = stream_new(cl_ht);
-                        sid->session=ss;
-                        if(ss->create_empty){
-                            log_it(L_INFO, "Opened stream session with only technical channels");
-
-                            cl_ht->reply_status_code=200;
-                            strcpy(cl_ht->reply_reason_phrase,"OK");
-                            //cl_ht->state_write=DAP_HTTP_CLIENT_STATE_START;
-                            //cl_ht->client->ready_to_write=true;
-                            cl_ht->state_read=DAP_HTTP_CLIENT_STATE_DATA;
-                            cl_ht->out_content_ready=true;
-                            stream_ch_new(sid,'s');
-                            stream_ch_new(sid,'t');
-                            stream_states_update(sid);
-                            dap_client_ready_to_read(cl_ht->client,true);
-                        }else{
-                            stream_ch_new(sid,'s');
-                            stream_ch_new(sid,'g');
-
-                            cl_ht->reply_status_code=200;
-                            strcpy(cl_ht->reply_reason_phrase,"OK");
-                            cl_ht->state_read=DAP_HTTP_CLIENT_STATE_DATA;
-                            dap_client_ready_to_read(cl_ht->client,true);
-
-                            stream_states_update(sid);
-
-                        }
+    log_it(L_DEBUG,"Prepare data stream");
+    if(cl_ht->in_query_string[0]){
+        log_it(L_INFO,"Query string [%s]",cl_ht->in_query_string);
+        if(sscanf(cl_ht->in_query_string,"fj913htmdgaq-d9hf=%u",&id)==1){
+            stream_session_t * ss=NULL;
+            ss=stream_session_id(id);
+            if(ss==NULL){
+                log_it(L_ERROR,"No session id %u was found",id);
+                cl_ht->reply_status_code=404;
+                strcpy(cl_ht->reply_reason_phrase,"Not found");
+            }else{
+                log_it(L_INFO,"Session id %u was found with media_id = %d",id,ss->media_id);
+                if(stream_session_open(ss)==0){ // Create new stream
+                    stream_t * sid = stream_new(cl_ht);
+                    sid->session=ss;
+                    if(ss->create_empty){
+                        log_it(L_INFO, "Opened stream session with only technical channels");
+
+                        cl_ht->reply_status_code=200;
+                        strcpy(cl_ht->reply_reason_phrase,"OK");
+                        //cl_ht->state_write=DAP_HTTP_CLIENT_STATE_START;
+                        //cl_ht->client->ready_to_write=true;
+                        cl_ht->state_read=DAP_HTTP_CLIENT_STATE_DATA;
+                        cl_ht->out_content_ready=true;
+                        stream_ch_new(sid,'s');
+                        stream_ch_new(sid,'t');
+                        stream_states_update(sid);
+                        dap_client_ready_to_read(cl_ht->client,true);
                     }else{
-                        log_it(L_ERROR,"Can't open session id %u",id);
-                        cl_ht->reply_status_code=404;
-                        strcpy(cl_ht->reply_reason_phrase,"Not found");
+                        stream_ch_new(sid,'s');
+                        stream_ch_new(sid,'g');
+
+                        cl_ht->reply_status_code=200;
+                        strcpy(cl_ht->reply_reason_phrase,"OK");
+                        cl_ht->state_read=DAP_HTTP_CLIENT_STATE_DATA;
+                        dap_client_ready_to_read(cl_ht->client,true);
+
+                        stream_states_update(sid);
+
                     }
+                }else{
+                    log_it(L_ERROR,"Can't open session id %u",id);
+                    cl_ht->reply_status_code=404;
+                    strcpy(cl_ht->reply_reason_phrase,"Not found");
                 }
             }
-        }else{
-            log_it(L_ERROR,"No query string");
         }
     }else{
-        log_it(L_WARNING,"Not authorized connection");
-        cl_ht->reply_status_code=505;
-        strcpy(cl_ht->reply_reason_phrase,"Not authorized");
-        cl_ht->state_write=DAP_HTTP_CLIENT_STATE_START;
-        dap_client_ready_to_write(cl_ht->client,true);
+        log_it(L_ERROR,"No query string");
     }
 }
 
@@ -179,7 +166,7 @@ stream_t * stream_new(dap_http_client_t * sh)
     ret->conn_http=sh;
 
 
-    sh->internal=ret;
+    sh->_internal=ret;
 
     log_it(L_NOTICE,"New stream instance");
     return ret;
diff --git a/stream/stream.h b/stream/stream.h
index 311807f0ae7cb07c92e0a6a6bb0ba0cddee980a3..653dd6f330906a642d40bfaa284b398c3ff5ffe7 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -33,7 +33,7 @@
 
 #define CHUNK_SIZE_MAX 3*1024
 
-struct dap_client;
+struct dap_client_remote;
 
 struct dap_http_client;
 struct dap_http;
@@ -47,7 +47,7 @@ typedef struct stream {
 
     int id;
     stream_session_t * session;
-    struct dap_client * conn; // Connection
+    struct dap_client_remote * conn; // Connection
 
     struct dap_http_client * conn_http; // HTTP-specific
 
@@ -68,7 +68,7 @@ typedef struct stream {
 
 } stream_t;
 
-#define STREAM(a) ((stream_t *) (a)->internal )
+#define STREAM(a) ((stream_t *) (a)->_internal )
 
 extern int stream_init();
 extern void stream_deinit();
diff --git a/stream/stream_ctl.c b/stream/stream_ctl.c
index 7a7608aa54ef613299452a153c9d71ef095c44f5..e9d19f77d9abe60cab2aa06857b942aee3592dcc 100644
--- a/stream/stream_ctl.c
+++ b/stream/stream_ctl.c
@@ -52,7 +52,7 @@ void stream_ctl_proc(struct dap_http_simple *cl_st, void * arg);
  */
 int stream_ctl_init()
 {
-    log_it(NOTICE,"Initialized stream control module");
+    log_it(L_NOTICE,"Initialized stream control module");
     return 0;
 }
 
@@ -114,7 +114,7 @@ void stream_ctl_proc(struct dap_http_simple *cl_st, void * arg)
             for(int i = 0; i < sizeof(key_str); i++)
                 key_str[i] = 65 + rand() % 25;
 
-            ss->key=enc_key_create(key_str,ENC_KEY_TYPE_AES);
+            ss->key=enc_key_create(key_str,DAP_ENC_KEY_TYPE_AES);
             enc_http_reply_f(dg,"%u %s",ss->id,key_str);
             dg->isOk=true;
        //     log_it(L_DEBUG,"Stream AES key string %s",key_str);
@@ -127,7 +127,7 @@ void stream_ctl_proc(struct dap_http_simple *cl_st, void * arg)
             for(int i = 0; i < sizeof(key_str); i++)
                 key_str[i] = 65 + rand() % 25;
 
-            ss->key=enc_key_create(key_str,ENC_KEY_TYPE_AES);
+            ss->key=enc_key_create(key_str,DAP_ENC_KEY_TYPE_AES);
             enc_http_reply_f(dg,"%u %s",ss->id,key_str);
             dg->isOk=true;
             log_it(L_DEBUG,"Stream AES key string %s",key_str);