bnet_close(UA_sock);
       UA_sock = NULL;
    }
+   if (WSACleanup() == 0) {
+      //csprint("Windows sockets cleaned up successfully...\n");
+   }
+   else {
+      csprint("Error while cleaning up windows sockets...\n");
+   }
 }
 
 /*
    }
    else {
       csprint("Error while initializing windows sockets...\n");
-      return 0;
    }
-   
+
    csprint("Connecting...\n");
 
    init_stack_dump();
    UnlockRes();
 
    memset(&jcr, 0, sizeof(jcr));
+   
+   jcr.dequeuing = 1; /* TODO: catch messages */
 
    UA_sock = bnet_connect(&jcr, 3, 3, "Director daemon", dir->address, NULL, dir->DIRport, 0);
    if (UA_sock == NULL) {
       csprint("Failed to connect to the director\n");
+      csprint(NULL, CS_END);
+      csprint(NULL, CS_DISCONNECTED);
       return NULL;
    }
 
    if (!authenticate_director(&jcr, dir, NULL)) {
       csprint("ERR=");
       csprint(UA_sock->msg);
+      csprint(NULL, CS_END);
+      csprint(NULL, CS_DISCONNECTED);
       return NULL;
    }
    
    
    UA_sock = NULL;
    
-   if (WSACleanup() == 0) {
-      //csprint("Windows sockets cleaned up successfully...\n");
-   }
-   else {
-      csprint("Error while cleaning up windows sockets...\n");
-   }
-
    return 0;
 }
 
 
             choices->Add(""); /* index 0 is never used by multiple choice questions */
          }
          
-         if (choices->GetCount() != num) { /* new choice has begun */
+         if ((long)choices->GetCount() != num) { /* new choice has begun */
             delete choices;
             choices = new wxArrayString(num);
             choices->Add("", num); /* fill until this number */