Index: /vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp
===================================================================
--- /vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 445)
+++ /vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 446)
@@ -211,8 +211,8 @@
     _services_DB->tablename="Services";
 
-    /* If program execution ends in anything other than a ordered shutdown, DB's will still 
+    /* ifprogram execution ends in anything other than a ordered shutdown, DB's will still 
      * be there for next run. Need to get rid of it so that old data isn't inadvertantly 
      * used in the next execution cycle. */
-    _services_DB->command = "DROP TABLE IF EXISTS Services;";     
+    _services_DB->command = "DROP TABLE ifEXISTS Services;";     
 
     rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail);
@@ -266,5 +266,5 @@
 
     _data_DB->tablename = "Data";
-    _data_DB->command = "DROP TABLE IF EXISTS Data;";     
+    _data_DB->command = "DROP TABLE ifEXISTS Data;";     
 
     rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail);
@@ -354,5 +354,5 @@
     //printf("********* %s **********\n", buffer);
     // TODO
-    // If we send integer op codes rather than strings, this process will be
+    // ifwe send integer op codes rather than strings, this process will be
     // MUCH faster since instead of donig string compares we can simply
     // switch on the integer value...
@@ -507,5 +507,5 @@
         selTimeout.tv_usec = 5000;
 
-        /* Check if there is a message on the shell ready to be processed */
+        /* Check ifthere is a message on the shell ready to be processed */
         rc = select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout);
     }
@@ -548,5 +548,5 @@
         selTimeout.tv_usec = 5000;
 
-        /* Check if there is a message on the shell ready to be processed */
+        /* Check ifthere is a message on the shell ready to be processed */
         rc = select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout);
     }
@@ -605,6 +605,6 @@
  * services that are requested in the mission. Each service in the mission is given 
  * the ID and FD of a component that has registered to provide that service. Deregistration 
- * is okay until this method is called without a reload, but if deregistration occurs after this
- * method is called it needs to be called again even if other engines also provide the services
+ * is okay until this method is called without a reload, but ifderegistration occurs after this
+ * method is called it needs to be called again even ifother engines also provide the services
  */
 void 
@@ -630,5 +630,5 @@
                 miss[activeMission].services[i].name.compare("dowhile") && \
                 miss[activeMission].services[i].name.compare("shell")) {
-                /* If it is a service, search the database of registered services to find 
+                /* ifit is a service, search the database of registered services to find 
                  * the ID of the component that registered it */
                 _services_DB->command="select ";
@@ -644,5 +644,5 @@
                         -1, &pStatement, NULL);
                 if(rc == SQLITE_OK) { 
-                    if (sqlite3_step(pStatement) == SQLITE_ROW)
+                    if(sqlite3_step(pStatement) == SQLITE_ROW)
                         miss[activeMission].services[i].componentID = sqlite3_column_int(pStatement, 0); 
                     else {
@@ -736,5 +736,5 @@
    } 
 
-    /* If this is a service command and not a shell command... */
+    /* ifthis is a service command and not a shell command... */
     /* Transmission starting messages */
     SendMessage(miss[activeMission].services[sourceID].socketFD, "request_optimization_service");
@@ -758,5 +758,5 @@
  * -All ordering constraints have been relaxed in this version; all data is stored 
  *  locally and only sent when requested
- * -If and while support fully implemented - up to three levels (if's can be nested, but dowhiles cannot)
+ * -ifand while support fully implemented - up to three levels (if's can be nested, but dowhiles cannot)
  * -For dowhiles, assumes loop condition determined on last line
  *
@@ -844,9 +844,9 @@
                              data = (const char *) sqlite3_column_text(pStatement, 1); 
                         else {
-                            LOG("1 data_DB:: Data not yet in DB.\n");
+                            WARNING("1 data_DB:: Data not yet in DB.\n");
                             rc=31337;
                         }
                     } else {
-                        LOG("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
+                        WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
                                 rc,_data_DB->command.c_str());
                     }
@@ -879,9 +879,9 @@
                          data2 = (const char *) sqlite3_column_text(pStatement, 1); 
                     else {
-                        LOG("2 data_DB:: Data not yet in DB.\n");
+                        WARNING("2 data_DB:: Data not yet in DB.\n");
                         rc = 31337;
                     }
                 } else {
-                    LOG("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
+                    WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
                             rc, _data_DB->command.c_str());
                 }
@@ -921,9 +921,9 @@
                                          data = (const char *) sqlite3_column_text(pStatement, 1); 
                                     else {
-                                        LOG("3 data_DB:: Data not yet in DB.\n");
+                                        WARNING("3 data_DB:: Data not yet in DB.\n");
                                         rc = 31337;
                                     }
                                 } else {
-                                    LOG("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
+                                    WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
                                             rc,_data_DB->command.c_str());
                                 }
@@ -947,124 +947,73 @@
                             _data_DB->command.append(miss[activeMission].services[k].output[t].erase(0, 1));
                             _data_DB->command.append("';");
-                            sqlite3_stmt * pStatement;
-                            rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
-                            if (rc == SQLITE_OK){ 
-                            if (sqlite3_step(pStatement) == SQLITE_ROW)
-                                 data2 = (const char *) sqlite3_column_text(pStatement, 1); 
-                            else {
-                                printf("4 data_DB:: Data not yet in DB.\n");
-                                rc=31337;
+
+                            sqlite3_stmt *pStatement;
+                            rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), \
+                                    -1, &pStatement, NULL);
+                            if(rc == SQLITE_OK) { 
+                                if(sqlite3_step(pStatement) == SQLITE_ROW)
+                                     data2 = (const char *) sqlite3_column_text(pStatement, 1); 
+                                else {
+                                    WARNING("4 data_DB:: Data not yet in DB.\n");
+                                    rc = 31337;
+                                }
+                            } else {
+                                WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
+                                        rc, _data_DB->command.c_str());
                             }
-                            } else {
-                            printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str());
-                            }
-                                sqlite3_finalize(pStatement);
-                            int pos = data2.find_last_of("@", data2.length()-2);
-                            token2 = data2.substr(pos+1);
-                            token2.erase(token2.length()-1);
-                                //printf("token=%s token2=%s\n", token.c_str(), token2.c_str());
-                                if(atof(token.c_str()) > atof(token2.c_str()))
-                                doit=true;
+
+                            sqlite3_finalize(pStatement);
+                            int32_t pos = data2.find_last_of("@", data2.length() - 2);
+                            token2 = data2.substr(pos + 1);
+                            token2.erase(token2.length() - 1);
+                            if(atof(token.c_str()) > atof(token2.c_str()))
+                                doit = true;
                         }
-                        else if (miss[activeMission].services[k].output[t].find(token) != string::npos)
-                        doit=true;
-                        if(doit){
-                        //printf("Level 1:if taken\n");
-                        for(uint16_t j = k+1; j <= k+miss[activeMission].services[k].num_conds; j++){ 
-                            if(miss[activeMission].services[j].name.compare("if")==0){
-                            //printf("Level 2:if detected\n");
-                                input.clear();
-                                check.clear();
-                                for(t = 0; t < 10; t++){
-                                if(!miss[activeMission].services[j].output[t].empty()){
-                                    input=miss[activeMission].services[j-numstatements[2]-1].output[t];
-                                           _data_DB->command="SELECT ";
-                                        _data_DB->command.append(_data_DB->tablename);
-                                       _data_DB->command.append(".* from ");
-                                       _data_DB->command.append(_data_DB->tablename);
-                                      _data_DB->command.append(" where Tag=='");
-                                     _data_DB->command.append(input);
-                                    _data_DB->command.append("';");
-                                    sqlite3_stmt * pStatement;
-                                    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
-                                    if (rc == SQLITE_OK){ 
-                                    if (sqlite3_step(pStatement) == SQLITE_ROW)
-                                         data = (const char *) sqlite3_column_text(pStatement, 1); 
-                                    else {
-                                        printf("5 data_DB:: Data not yet in DB.\n");
-                                        rc=31337;
-                                    }
-                                    } else {
-                                    printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str());
-                                    }
-                                        sqlite3_finalize(pStatement);
-                                    //printf("data=%s\n", data.c_str());
-                                    int pos = data.find_last_of("@", data.length()-2);
-                                    token = data.substr(pos+1);
-                                    token.erase(token.length()-1);
-                                    //printf("token=%s\n", token.c_str());
-                                    data.clear();
-                                    break;
-                                }
-                                }
-                                bool doit = false;
-                                if(miss[activeMission].services[j].output[t].find(">") != string::npos){
-                                    _data_DB->command="SELECT ";
-                                    _data_DB->command.append(_data_DB->tablename);
-                                    _data_DB->command.append(".* from ");
-                                   _data_DB->command.append(_data_DB->tablename);
-                                    _data_DB->command.append(" where Tag=='");
-                                    _data_DB->command.append(miss[activeMission].services[j].output[t].erase(0, 1));
-                                    _data_DB->command.append("';");
-                                    sqlite3_stmt * pStatement;
-                                    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
-                                    if (rc == SQLITE_OK){ 
-                                    if (sqlite3_step(pStatement) == SQLITE_ROW)
-                                         data2 = (const char *) sqlite3_column_text(pStatement, 1); 
-                                    else {
-                                        printf("6 data_DB:: Data not yet in DB.\n");
-                                        rc=31337;
-                                    }
-                                    } else {
-                                    printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str());
-                                    }
-                                        sqlite3_finalize(pStatement);
-
-                                int pos = data2.find_last_of("@", data2.length()-2);
-                                token2 = data2.substr(pos+1);
-                                token2.erase(token2.length()-1);
-                                    if(atof(token.c_str()) > atof(token2.c_str()))
-                                    doit=true;
-                                data.clear();
-                                }
-                                else if (miss[activeMission].services[j].output[t].find(token) != string::npos)
-                                doit=true;
-                                if(doit){
-                                //printf("Level 1:if taken\n");
-                                for(uint16_t l = j+1; l <= j+miss[activeMission].services[j].num_conds; l++){ 
-                                    TransactData(l);
-                                }
-                                }
-                                else
-                                //printf("Level 2:if not taken\n");
-                                numstatements[2] +=miss[activeMission].services[j].num_conds+1;
-                                j+=miss[activeMission].services[j].num_conds;
-                                //printf("Level 2:doneif %d, %d, %d\n", numstatements, miss[activeMission].services[i].num_conds, i);
-                            }else if(miss[activeMission].services[j].name.compare("dowhile")==0){
-                                numstatements[0]=0;
-                                //printf("Level 2:while detected\n");
-                                while(true){
-                                    uint16_t l;
-                                    for(l = j+1; l <= j+miss[activeMission].services[j].num_conds; l++){ 
-                                    TransactData(l);
-                                    }
-                                    data.clear();
+                        else if(miss[activeMission].services[k].output[t].find(token) != string::npos)
+                            doit=true;
+
+                        if(doit) {
+                            for(size_t j = k + 1; j <= k+miss[activeMission].services[k].num_conds; j++) { 
+                                if(miss[activeMission].services[j].name.compare("if") == 0) {
                                     input.clear();
                                     check.clear();
-                                    int t;
-                                    for(t = 0; t < 10; t++){
-                                    if(!miss[activeMission].services[j].output[t].empty()){
-                                        input=miss[activeMission].services[l-2].output[t];
-                                        //printf("%s\n",input.c_str());
+                                    for(t = 0; t < 10; t++) {
+                                        if(!miss[activeMission].services[j].output[t].empty()) {
+                                            input = miss[activeMission].services[j - numstatements[2] - 1].output[t];
+
+                                            _data_DB->command="SELECT ";
+                                            _data_DB->command.append(_data_DB->tablename);
+                                            _data_DB->command.append(".* from ");
+                                            _data_DB->command.append(_data_DB->tablename);
+                                            _data_DB->command.append(" where Tag=='");
+                                            _data_DB->command.append(input);
+                                            _data_DB->command.append("';");
+
+                                            sqlite3_stmt *pStatement;
+
+                                            rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
+                                            if(rc == SQLITE_OK) { 
+                                                if(sqlite3_step(pStatement) == SQLITE_ROW)
+                                                     data = (const char *) sqlite3_column_text(pStatement, 1); 
+                                                else {
+                                                    WARNING("5 data_DB:: Data not yet in DB.\n");
+                                                    rc = 31337;
+                                                }
+                                            } else {
+                                                WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
+                                                        rc, _data_DB->command.c_str());
+                                            }
+
+                                            sqlite3_finalize(pStatement);
+                                            int32_t pos = data.find_last_of("@", data.length()-2);
+                                            token = data.substr(pos+1);
+                                            token.erase(token.length()-1);
+                                            data.clear();
+                                            break;
+                                        }
+                                    }
+
+                                    bool doit = false;
+                                    if(miss[activeMission].services[j].output[t].find(">") != string::npos) {
                                         _data_DB->command="SELECT ";
                                         _data_DB->command.append(_data_DB->tablename);
@@ -1072,169 +1021,219 @@
                                         _data_DB->command.append(_data_DB->tablename);
                                         _data_DB->command.append(" where Tag=='");
-                                        _data_DB->command.append(input);
+                                        _data_DB->command.append(miss[activeMission].services[j].output[t].erase(0, 1));
                                         _data_DB->command.append("';");
-                                        sqlite3_stmt * pStatement;
-
+
+                                        sqlite3_stmt *pStatement;
                                         rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
-                                        if (rc == SQLITE_OK){ 
-                                        if (sqlite3_step(pStatement) == SQLITE_ROW)
-                                             data = (const char *) sqlite3_column_text(pStatement, 1); 
-                                        else {
-                                            printf("7 data_DB:: Data not yet in DB.: %s\n", _data_DB->command.c_str());
-                                            rc=31337;
+                                        if(rc == SQLITE_OK) { 
+                                            if(sqlite3_step(pStatement) == SQLITE_ROW)
+                                                 data2 = (const char *) sqlite3_column_text(pStatement, 1); 
+                                            else {
+                                                WARNING("6 data_DB:: Data not yet in DB.\n");
+                                                rc=31337;
+                                            }
+                                        } else {
+                                            WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
+                                                    rc, _data_DB->command.c_str());
                                         }
-                                        } else {
-                                          printf("data_DB:: SQL statement error. rc = %i\n%s\n",rc,_data_DB->command.c_str());
+
+                                        sqlite3_finalize(pStatement);
+
+                                        int32_t pos = data2.find_last_of("@", data2.length()-2);
+                                        token2 = data2.substr(pos + 1);
+                                        token2.erase(token2.length()-1);
+
+                                        if(atof(token.c_str()) > atof(token2.c_str()))
+                                            doit=true;
+
+                                        data.clear();
+                                    }
+
+                                    else if(miss[activeMission].services[j].output[t].find(token) != string::npos)
+                                        doit = true;
+
+                                    if(doit) {
+                                        for(size_t l = j + 1; l <= j + miss[activeMission].services[j].num_conds; l++) { 
+                                            TransactData(l);
                                         }
-                                            sqlite3_finalize(pStatement);
-                                        //printf("Level 2:data=%s\n", data.c_str());
-                                            int pos = data.find_last_of("@", data.length()-2);
-                                            token = data.substr(pos+1);
-                                            token.erase(token.length()-1);
-                                        //printf("Level 2:token=%s\n", token);
-                                        break;
                                     }
+
+                                    numstatements[2] += miss[activeMission].services[j].num_conds + 1;
+                                    j += miss[activeMission].services[j].num_conds;
+                                } else if(miss[activeMission].services[j].name.compare("dowhile") == 0) {
+                                    numstatements[0]=0;
+
+                                    while(true) {
+                                        uint32_t l;
+                                        for(l = j + 1; l <= j+miss[activeMission].services[j].num_conds; l++) { 
+                                            TransactData(l);
+                                        }
+
+                                        data.clear();
+                                        input.clear();
+                                        check.clear();
+
+                                        int32_t t;
+                                        for(t = 0; t < 10; t++) {
+                                            if(!miss[activeMission].services[j].output[t].empty()){
+                                                input=miss[activeMission].services[l-2].output[t];
+                                                _data_DB->command="SELECT ";
+                                                _data_DB->command.append(_data_DB->tablename);
+                                                _data_DB->command.append(".* from ");
+                                                _data_DB->command.append(_data_DB->tablename);
+                                                _data_DB->command.append(" where Tag=='");
+                                                _data_DB->command.append(input);
+                                                _data_DB->command.append("';");
+                                                sqlite3_stmt *pStatement;
+
+                                                rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
+                                                if(rc == SQLITE_OK){ 
+                                                    if(sqlite3_step(pStatement) == SQLITE_ROW)
+                                                         data = (const char *) sqlite3_column_text(pStatement, 1); 
+                                                    else {
+                                                        WARNING("7 data_DB:: Data not yet in DB.: %s\n", _data_DB->command.c_str());
+                                                        rc = 31337;
+                                                    }
+                                                } else {
+                                                    WARNING("data_DB:: SQL statement error. rc = %i\n%s\n", \
+                                                            rc, _data_DB->command.c_str());
+                                                }
+
+                                                sqlite3_finalize(pStatement);
+                                                int32_t pos = data.find_last_of("@", data.length() - 2);
+                                                token = data.substr(pos + 1);
+                                                token.erase(token.length() - 1);
+                                                break;
+                                            }
+                                        }
+
+                                        if(miss[activeMission].services[j].output[t].find(token) == string::npos) {
+                                            break;
+                                        }
                                     }
-                                    //printf("Level 2:--- %s  %s---\n", miss[activeMission].services[j].output[t].c_str(), token);
-                                    if(miss[activeMission].services[j].output[t].find(token) != string::npos){
-                                    //printf("Level 2:while taken again!\n");
-                                    }
-                                    else {
-                                    //printf("Level 2:no more while\n");
-                                    break;}
+
+                                    j += miss[activeMission].services[j].num_conds;
+                                } else {
+                                    numstatements[2] = 0;
+                                    TransactData(j);
                                 }
-                                j+=miss[activeMission].services[j].num_conds;
-                            }
-                            else{
-                                //printf("Level 2: no conditional\n");
-                                numstatements[2]=0;
-                                    TransactData(j);
                             }
                         }
-                        }
-                        else{
-                        //printf("Level 1: if not taken\n");
-                        }
-                            numstatements[1] +=miss[activeMission].services[k].num_conds+1;
-                            k+=miss[activeMission].services[k].num_conds;
-                        //printf("doneif %d, %d, %d\n", numstatements, miss[activeMission].services[i].num_conds, i);
-                    }else if(miss[activeMission].services[k].name.compare("dowhile")==0){
-                        numstatements[0]=0;
-                        //printf("Level 1: while detected\n");
-                        while(true){
-                        uint16_t j;
-                            for(j = k+1; j <= k+miss[activeMission].services[k].num_conds; j++){ 
-                            TransactData(j);
+
+                        numstatements[1] += miss[activeMission].services[k].num_conds + 1;
+                        k += miss[activeMission].services[k].num_conds;
+                    } else if(miss[activeMission].services[k].name.compare("dowhile") == 0) {
+                        numstatements[0] = 0;
+                        while(true) {
+                            int32_t j;
+                            for(j = k + 1; j <= k + miss[activeMission].services[k].num_conds; j++) {
+                                TransactData(j);
                             }
+
                             data.clear();
                             input.clear();
                             check.clear();
-                            int t;
-                            for(t = 0; t < 10; t++){
-                            if(!miss[activeMission].services[k].output[t].empty()){
-                                input=miss[activeMission].services[j-1].output[t];
-                                _data_DB->command="SELECT ";
-                                _data_DB->command.append(_data_DB->tablename);
-                                _data_DB->command.append(".* from ");
-                                _data_DB->command.append(_data_DB->tablename);
-                                _data_DB->command.append(" where Tag=='");
-                                _data_DB->command.append(input);
-                                _data_DB->command.append("';");
-                                sqlite3_stmt * pStatement;
-                                rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
-                                if (rc == SQLITE_OK){ 
-                                if (sqlite3_step(pStatement) == SQLITE_ROW)
-                                     data = (const char *) sqlite3_column_text(pStatement, 1); 
-                                else {
-                                    printf("8 data_DB:: Data not yet in DB.\n");
-                                    rc=31337;
+                            int32_t t;
+                            for(t = 0; t < 10; t++) {
+                                if(!miss[activeMission].services[k].output[t].empty()) {
+                                    input = miss[activeMission].services[j - 1].output[t];
+                                    _data_DB->command="SELECT ";
+                                    _data_DB->command.append(_data_DB->tablename);
+                                    _data_DB->command.append(".* from ");
+                                    _data_DB->command.append(_data_DB->tablename);
+                                    _data_DB->command.append(" where Tag=='");
+                                    _data_DB->command.append(input);
+                                    _data_DB->command.append("';");
+
+                                    sqlite3_stmt *pStatement;
+                                    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
+                                    if(rc == SQLITE_OK) { 
+                                        if(sqlite3_step(pStatement) == SQLITE_ROW)
+                                             data = (const char *) sqlite3_column_text(pStatement, 1); 
+                                        else {
+                                            WARNING("8 data_DB:: Data not yet in DB.\n");
+                                            rc = 31337;
+                                        }
+                                    } else {
+                                        WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
+                                                rc, _data_DB->command.c_str());
+                                    }
+
+                                    sqlite3_finalize(pStatement);
+                                    int32_t pos = data.find_last_of("@", data.length() - 2);
+                                    token = data.substr(pos + 1);
+                                    token.erase(token.length() - 1);
+                                    break;
                                 }
-                                } else {
-                                printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str());
-                                }
-                                    sqlite3_finalize(pStatement);
-                                //printf("Level 1:data=%s\n", data.c_str());
-                                int pos = data.find_last_of("@", data.length()-2);
-                                token = data.substr(pos+1);
-                                token.erase(token.length()-1);
-                                //printf("Level 1:token=%s\n", token);
+                            }
+
+                            if(miss[activeMission].services[k].output[t].find(token) == string::npos) {
                                 break;
                             }
-                            }
-                            //printf("Level 1:--- %s  %s---\n", miss[activeMission].services[k].output[t].c_str(), token);
-                            if(miss[activeMission].services[k].output[t].find(token) != string::npos){
-                            //printf("Level 1:while taken again!\n");
-                            }
-                            else {
-                            //printf("Level 1:While finished\n");
-                            break;}
                         }
-                        k+=miss[activeMission].services[k].num_conds;
-                    }
-                    else{
-                        //printf("Level1:No conditional\n");
-                        numstatements[1]=0;
-                            TransactData(k);
+
+                        k += miss[activeMission].services[k].num_conds;
+                    } else{
+                        numstatements[1] = 0;
+                        TransactData(k);
                     }
                 }
             }
-                numstatements[0] +=miss[activeMission].services[i].num_conds+1;
-            i+=miss[activeMission].services[i].num_conds;
-        }
-        else if(miss[activeMission].services[i].name.compare("dowhile")==0)
-        {
-            numstatements[0]=0;
-            //printf("Level 0: while detected\n");
-            while(true){
-            uint16_t k;
-                for(k = i+1; k <= i+miss[activeMission].services[i].num_conds; k++){ 
-                TransactData(k);
+
+            numstatements[0] += miss[activeMission].services[i].num_conds + 1;
+            i += miss[activeMission].services[i].num_conds;
+        } else if(miss[activeMission].services[i].name.compare("dowhile") == 0) {
+            numstatements[0] = 0;
+            while(true) {
+                uint32_t k;
+                for(k = i + 1; k <= i + miss[activeMission].services[i].num_conds; k++){ 
+                    TransactData(k);
                 }
+
                 data.clear();
                 input.clear();
                 check.clear();
-                int t;
+                int32_t t;
                 for(t = 0; t < 10; t++){
-                if(!miss[activeMission].services[i].output[t].empty()){
-                    input=miss[activeMission].services[k-1].output[t];
-                    _data_DB->command="SELECT ";
-                    _data_DB->command.append(_data_DB->tablename);
-                    _data_DB->command.append(".* from ");
-                    _data_DB->command.append(_data_DB->tablename);
-                    _data_DB->command.append(" where Tag=='");
-                    _data_DB->command.append(input);
-                    _data_DB->command.append("';");
-                    sqlite3_stmt * pStatement;
-                    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
-                    if (rc == SQLITE_OK){ 
-                    if (sqlite3_step(pStatement) == SQLITE_ROW)
-                         data = (const char *) sqlite3_column_text(pStatement, 1); 
-                    else {
-                        printf("10data_DB:: Data not yet in DB.\n");
-                        rc=31337;
+                    if(!miss[activeMission].services[i].output[t].empty()) {
+                        input = miss[activeMission].services[k - 1].output[t];
+                        _data_DB->command="SELECT ";
+                        _data_DB->command.append(_data_DB->tablename);
+                        _data_DB->command.append(".* from ");
+                        _data_DB->command.append(_data_DB->tablename);
+                        _data_DB->command.append(" where Tag=='");
+                        _data_DB->command.append(input);
+                        _data_DB->command.append("';");
+
+                        sqlite3_stmt *pStatement;
+                        rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL);
+                        if(rc == SQLITE_OK) { 
+                            if(sqlite3_step(pStatement) == SQLITE_ROW)
+                                 data = (const char *) sqlite3_column_text(pStatement, 1); 
+                            else {
+                                WARNING("10data_DB:: Data not yet in DB.\n");
+                                rc = 31337;
+                            }
+                        } else {
+                            WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
+                                    rc, _data_DB->command.c_str());
+                        }
+
+                        sqlite3_finalize(pStatement);
+                        int32_t pos = data.find_last_of("@", data.length()-2);
+                        token = data.substr(pos + 1);
+                        token.erase(token.length() - 1);
+                        break;
                     }
-                    } else {
-                    printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str());
-                    }
-                        sqlite3_finalize(pStatement);
-                    int pos = data.find_last_of("@", data.length()-2);
-                    token = data.substr(pos+1);
-                    token.erase(token.length()-1);
+                }
+
+                if(miss[activeMission].services[i].output[t].find(token) == string::npos) {
                     break;
                 }
-                }
-                //printf("Level 0:--- %s  %s---\n", miss[activeMission].services[i].output[t].c_str(), token);
-                if(miss[activeMission].services[i].output[t].find(token) != string::npos){
-                //printf("Level 0:while taken again!\n");
-                }
-                else {
-                //printf("Level 0:no more while\n");
-                break;}
             }
-            i+=miss[activeMission].services[i].num_conds;
-        }
-        else{
-            numstatements[0]=0;
-            //printf("Level 0: No conditional\n");
+
+            i += miss[activeMission].services[i].num_conds;
+        } else{
+            numstatements[0] = 0;
             TransactData(i);
         }
@@ -1244,33 +1243,20 @@
     data.clear();
 
-    if(!shellFound)
-    {
-    int k = 0;
-    while(k<10 && !miss[activeMission].input[k].empty()){
-        k++;
-    }
-    sprintf(buffer, "%d", k);
-    SendMessage(shellSocketFD, buffer);
-    for(int t = 0; t < k; t++){
-        SendMessage(shellSocketFD, miss[activeMission].input[t].c_str()); 
-        SendMessage(shellSocketFD, "0");
-    }
-    }
-
+    if(!shellFound) {
+        int k = 0;
+        while(k < 10 && !miss[activeMission].input[k].empty()) {
+            k++;
+        }
+
+        sprintf(buffer, "%d", k);
+        SendMessage(shellSocketFD, buffer);
+
+        for(size_t t = 0; t < k; t++) {
+            SendMessage(shellSocketFD, miss[activeMission].input[t].c_str()); 
+            SendMessage(shellSocketFD, "0");
+        }
+    }
 
     LOG("ServiceManagementLayer:: Done performing active mission.\n");
-    /*
-    strcpy(_data_DB->command, "select ");
-    strcat(_data_DB->command, _data_DB->tablename);
-    strcat(_data_DB->command, ".* from ");
-    strcat(_data_DB->command, _data_DB->tablename);
-    strcat(_data_DB->command, ";");
-
-    // execute print (select all)  command  
-    rc = sqlite3_exec(_data_DB->db, _data_DB->command, callback, 0, &errorMsg);
-    if( rc!=SQLITE_OK && rc!=101 )
-        fprintf(stderr, "SQL error: %s\n", errorMsg);
-    printf("database %s, table %s:\n", _data_DB->filename, _data_DB->tablename);
-    printf("\n\n\n");*/
 }
 
@@ -1291,10 +1277,11 @@
     _services_DB->command.append(";");
 
-    // execute print (select all)  command    
+    // Execute print (select all) command
     char *errorMsg;
-    int rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg);
-    if( rc!=SQLITE_OK && rc!=101 )
-        fprintf(stderr, "SQL error: %s\n", errorMsg);
-    printf("database %s, table %s:\n", _services_DB->filename.c_str(), _services_DB->tablename.c_str());
+    int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg);
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("SQL error: %s\n", errorMsg);
+
+    LOG("database %s, table %s:\n", _services_DB->filename.c_str(), _services_DB->tablename.c_str());
 }
 
@@ -1309,8 +1296,11 @@
 {
     LOG("ServiceManagementLayer:: Reloading Configuration.\n");
+
     free(miss);
+
     miss = new Mission[10];
-    for(int i = 0; i < 10; i++)
+    for(size_t i = 0; i < 10; i++)
         miss[i].services = new Service[30];
+
     LoadConfiguration(_SML_Config.c_str(), miss);
 }
@@ -1336,10 +1326,12 @@
     TiXmlElement *pChild0, *pChild1, *pChild2, *pChild3, *pChild4;
     TiXmlHandle hRoot(0);
-    printf("ServiceManagementLayer:: Loading Configuration.\n");
+
+    LOG("ServiceManagementLayer:: Loading Configuration.\n");
+
     TiXmlDocument doc(".");
     doc.LoadFile(SML_Config);
     bool loadOkay = doc.LoadFile();
     if(!loadOkay)
-        printf("Loading SML configuration failed: %s\n", SML_Config);
+        WARNING("Loading SML configuration failed: %s\n", SML_Config);
 
     TiXmlHandle hDoc(&doc);
@@ -1348,136 +1340,145 @@
 
     if(!pMission) 
-        printf("No valid root!");
+        WARNING("No valid root!");
 
     hRoot = TiXmlHandle(pMission);
     pService = pMission->FirstChildElement();
+
     int32_t mission_num = 0;
-    //Iterate through the missions
-    for(pChild0 = pMission->FirstChildElement(); pChild0 ; \
-        pChild0 = pChild0->NextSiblingElement()) 
-    {
-    int32_t service_num = 0;
-    uint16_t cond_array[] = {0, 0, 0};
+
+    /* Iterate through the missions */
+    for(pChild0 = pMission->FirstChildElement(); pChild0 ; pChild0 = pChild0->NextSiblingElement())  {
+        int32_t service_num = 0;
+        uint16_t cond_array[] = {0, 0, 0};
     
         for(pChild1  = (pChild0->FirstChildElement())->FirstChildElement(); pChild1; \
-              pChild1  = pChild1->NextSiblingElement()) 
-        {
-        int32_t conditional_0 = service_num;
-        for(pChild2 = pChild1->FirstChildElement(); \
-        pChild2; pChild2 = pChild2->NextSiblingElement())
-        {
-        service_num++;
-        int32_t conditional_1 = service_num;
-        for(pChild3 = pChild2->FirstChildElement(); \
-            pChild3; pChild3 = pChild3->NextSiblingElement())
-        {
-            service_num++;
-            int32_t conditional_2 = service_num;
-            for(pChild4 = pChild3->FirstChildElement(); \
-                pChild4; pChild4 = pChild4->NextSiblingElement())
-            {
-                   service_num++;
-                if(pChild4->Attribute("name"))
-                    mList[mission_num].services[service_num].name = pChild4->Attribute("name");
-                else
-                    mList[mission_num].services[service_num].name = pChild4->Value();
+                pChild1  = pChild1->NextSiblingElement()) {
+
+            int32_t conditional_0 = service_num;
+            for(pChild2 = pChild1->FirstChildElement(); pChild2; pChild2 = pChild2->NextSiblingElement()) {
+                service_num++;
+
+                int32_t conditional_1 = service_num;
+                for(pChild3 = pChild2->FirstChildElement(); pChild3; pChild3 = pChild3->NextSiblingElement()) {
+                    service_num++;
+                    int32_t conditional_2 = service_num;
+                    for(pChild4 = pChild3->FirstChildElement(); pChild4; pChild4 = pChild4->NextSiblingElement()) {
+                        service_num++;
+                        if(pChild4->Attribute("name"))
+                            mList[mission_num].services[service_num].name = pChild4->Attribute("name");
+                        else
+                            mList[mission_num].services[service_num].name = pChild4->Value();
+
+                        for(size_t i = 1; i <= 10; i++) {
+                            char buffer[9]="input";
+                            sprintf(buffer, "%s%d", buffer, i); 
+                            if(pChild4->Attribute(buffer))
+                                mList[mission_num].services[service_num].input[i - 1] = pChild4->Attribute(buffer);
+
+                            char buffer2[9]="output";
+                            sprintf(buffer2, "%s%d", buffer2, i); 
+                            if(pChild4->Attribute(buffer2))
+                                mList[mission_num].services[service_num].output[i - 1] = pChild4->Attribute(buffer2);
+                        }
+
+                        if(pChild4->Attribute("parameter"))
+                            mList[mission_num].services[service_num].parameter = pChild4->Attribute("parameter");
+
+                        cond_array[2]++;
+                    }
+
+                    if(!strcmp(pChild3->Value(), "shell") || conditional_2 != service_num) {
+                        mList[mission_num].services[conditional_2].name = pChild3->Value();
+                    } else {
+                        mList[mission_num].services[service_num].name = pChild3->Attribute("name");
+                    }
+
+                    for(size_t i = 1; i <= 10; i++) {
+                        char buffer[9]="input";
+                        sprintf(buffer, "%s%d", buffer, i); 
+                        if(pChild3->Attribute(buffer))
+                            mList[mission_num].services[conditional_2].input[i - 1] = pChild3->Attribute(buffer);
+
+                        char buffer2[9]="output";
+                        sprintf(buffer2, "%s%d", buffer2, i); 
+                        if(pChild3->Attribute(buffer2))
+                            mList[mission_num].services[conditional_2].output[i - 1] = pChild3->Attribute(buffer2);
+                    }
+
+                    if(pChild3->Attribute("parameter"))
+                        mList[mission_num].services[conditional_2].parameter = pChild3->Attribute("parameter");
+
+                    mList[mission_num].services[conditional_2].num_conds = cond_array[2];
+                    cond_array[1] += cond_array[2] + 1;
+                    cond_array[2] = 0;
+                }
+
+                if(!strcmp(pChild2->Value(), "shell") || (conditional_1 != service_num)) {
+                    mList[mission_num].services[conditional_1].name = pChild2->Value();
+                } else{
+                    mList[mission_num].services[service_num].name = pChild2->Attribute("name");
+                }
+
                 for(int i = 1; i <= 10; i++) {
                     char buffer[9]="input";
                     sprintf(buffer, "%s%d", buffer, i); 
-                    //printf("buffer=%s\n", buffer);
-                    if(pChild4->Attribute(buffer))
-                        mList[mission_num].services[service_num].input[i-1] = pChild4->Attribute(buffer);
+                    if(pChild2->Attribute(buffer))
+                        mList[mission_num].services[conditional_1].input[i - 1] = pChild2->Attribute(buffer);
+
                     char buffer2[9]="output";
                     sprintf(buffer2, "%s%d", buffer2, i); 
-                    if(pChild4->Attribute(buffer2))
-                    mList[mission_num].services[service_num].output[i-1] = pChild4->Attribute(buffer2);
+                    if(pChild2->Attribute(buffer2))
+                        mList[mission_num].services[conditional_1].output[i - 1] = pChild2->Attribute(buffer2);
                 }
-                if(pChild4->Attribute("parameter"))
-                mList[mission_num].services[service_num].parameter = pChild4->Attribute("parameter");
-                cond_array[2]++;
+
+                if(pChild2->Attribute("parameter"))
+                    mList[mission_num].services[conditional_1].parameter = pChild2->Attribute("parameter");
+
+                mList[mission_num].services[conditional_1].num_conds = cond_array[1];
+                cond_array[0] += cond_array[1] + 1;
+                cond_array[1] = 0;
             }
-            if(!strcmp(pChild3->Value(), "shell") || conditional_2 != service_num) {
-                mList[mission_num].services[conditional_2].name = pChild3->Value();
+        
+            if(!strcmp(pChild1->Value(), "shell") || conditional_0 != service_num) {
+                mList[mission_num].services[conditional_0].name = pChild1->Value();
+            } else{
+                mList[mission_num].services[conditional_0].name = pChild1->Attribute("name");
             }
-            else{
-                mList[mission_num].services[service_num].name = pChild3->Attribute("name");
-            }
-            for(int i = 1; i <= 10; i++) {
+
+            for(size_t i = 1; i <= 10; i++) {
                 char buffer[9]="input";
                 sprintf(buffer, "%s%d", buffer, i); 
-                if(pChild3->Attribute(buffer))
-                mList[mission_num].services[conditional_2].input[i-1] = pChild3->Attribute(buffer);
+                if(pChild1->Attribute(buffer))
+                    mList[mission_num].services[conditional_0].input[i-1] = pChild1->Attribute(buffer);
+
                 char buffer2[9]="output";
                 sprintf(buffer2, "%s%d", buffer2, i); 
-                if(pChild3->Attribute(buffer2))
-                mList[mission_num].services[conditional_2].output[i-1] = pChild3->Attribute(buffer2);
+                if(pChild1->Attribute(buffer2))
+                    mList[mission_num].services[conditional_0].output[i-1] = pChild1->Attribute(buffer2);
             }
-                if(pChild3->Attribute("parameter"))
-                mList[mission_num].services[conditional_2].parameter = pChild3->Attribute("parameter");
-            mList[mission_num].services[conditional_2].num_conds = cond_array[2];
-            cond_array[1]+=cond_array[2]+1;
-            cond_array[2] = 0;
-
-
+
+            if(pChild1->Attribute("parameter"))
+                mList[mission_num].services[conditional_0].parameter = pChild1->Attribute("parameter");
+            mList[mission_num].services[conditional_0].num_conds = cond_array[0];
+                cond_array[0] = 0;
+
+            service_num++;
         }
-        if(!strcmp(pChild2->Value(), "shell") || conditional_1 != service_num) {
-            mList[mission_num].services[conditional_1].name = pChild2->Value();
+    
+        mList[mission_num].numServices = service_num;
+        mList[mission_num].name = pChild0->Attribute("name");
+        mList[mission_num].missionID = atoi(pChild0->Attribute("id"));
+
+        for(size_t i = 1; i <= 10; i++) {
+            char buffer[9]="param";
+            sprintf(buffer, "%s%d", buffer, i); 
+            if(pChild0->Attribute(buffer)){
+                mList[mission_num].input[i-1] = pChild0->Attribute(buffer);
+            }
         }
-        else{
-            mList[mission_num].services[service_num].name = pChild2->Attribute("name");
-        }
-           for(int i = 1; i <= 10; i++) {
-            char buffer[9]="input";
-            sprintf(buffer, "%s%d", buffer, i); 
-            if(pChild2->Attribute(buffer))
-                mList[mission_num].services[conditional_1].input[i-1] = pChild2->Attribute(buffer);
-            char buffer2[9]="output";
-            sprintf(buffer2, "%s%d", buffer2, i); 
-            if(pChild2->Attribute(buffer2))
-            mList[mission_num].services[conditional_1].output[i-1] = pChild2->Attribute(buffer2);
-        }
-            if(pChild2->Attribute("parameter"))
-            mList[mission_num].services[conditional_1].parameter = pChild2->Attribute("parameter");
-
-        mList[mission_num].services[conditional_1].num_conds = cond_array[1];
-        cond_array[0]+=cond_array[1]+1;
-        cond_array[1] = 0;
-        }
-        
-        if(!strcmp(pChild1->Value(), "shell") || conditional_0 != service_num) {
-            mList[mission_num].services[conditional_0].name = pChild1->Value();
-        }
-        else{
-        mList[mission_num].services[conditional_0].name = pChild1->Attribute("name");
-        }
-        for(int i = 1; i <= 10; i++) {
-            char buffer[9]="input";
-            sprintf(buffer, "%s%d", buffer, i); 
-            if(pChild1->Attribute(buffer))
-                mList[mission_num].services[conditional_0].input[i-1] = pChild1->Attribute(buffer);
-            char buffer2[9]="output";
-            sprintf(buffer2, "%s%d", buffer2, i); 
-            if(pChild1->Attribute(buffer2))
-            mList[mission_num].services[conditional_0].output[i-1] = pChild1->Attribute(buffer2);
-        }
-        if(pChild1->Attribute("parameter"))
-            mList[mission_num].services[conditional_0].parameter = pChild1->Attribute("parameter");
-        mList[mission_num].services[conditional_0].num_conds = cond_array[0];
-            cond_array[0] = 0;
-        service_num++;
-    }
-    
-    mList[mission_num].numServices = service_num;
-    mList[mission_num].name = pChild0->Attribute("name");
-        mList[mission_num].missionID = atoi(pChild0->Attribute("id"));
-    for(int i = 1; i <= 10; i++) {
-        char buffer[9]="param";
-        sprintf(buffer, "%s%d", buffer, i); 
-        if(pChild0->Attribute(buffer)){
-            mList[mission_num].input[i-1] = pChild0->Attribute(buffer);
-        }
-    }
-    mission_num++;
-    }
+
+        mission_num++;
+    }
+
     LOG("ServiceManagementLayer:: Done Loading Configuration\n");
 }
@@ -1513,5 +1514,5 @@
  *
  * DESCRIPTION: Deletes individual services from the DB
- * NOTE THAT this function only needs to be called if service deregistration is going
+ * NOTE THAT this function only needs to be called ifservice deregistration is going
  * to be done at a different time than component deregistration; it is handled
  * more efficiently and directly during that deregistration process.
@@ -1526,4 +1527,5 @@
     _services_DB->command.append(_services_DB->tablename);
     _services_DB->command.append(" WHERE ID_Num IN (SELECT ");
+
     char tmp[3];
     memset(tmp,0,3);
@@ -1536,8 +1538,9 @@
     _services_DB->command.append(buffer);
     _services_DB->command.append("');");
+
     char *errorMsg;
-    int rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg);
-    if( rc!=SQLITE_OK && rc!=101 )
-        fprintf(stderr, "SQL error: %s\n", errorMsg);
+    int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg);
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("SQL error: %s\n", errorMsg);
 }
 
@@ -1564,5 +1567,5 @@
     SendMessage(CE_List[ID].FD, buffer);
     if(strcmp("deregister_ack", buffer) != 0) {
-    ERROR(1, "SML:: Failed to close CE socket\n");
+        ERROR(1, "SML:: Failed to close CE socket\n");
     }
 
@@ -1573,4 +1576,5 @@
     _services_DB->command.append("ID_Num");
     _services_DB->command.append("==");
+
     char tmp[3];
     memset(tmp,0,3);
@@ -1578,9 +1582,9 @@
     _services_DB->command.append(tmp);
     _services_DB->command.append(";");
+
     char *errorMsg;
-    int rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg);
-    if( rc!=SQLITE_OK && rc!=101 )
-        fprintf(stderr, "SQL error: %s\n", errorMsg);
-
+    int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg);
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("SQL error: %s\n", errorMsg);
 
     CE_List[ID].FD = -1;
@@ -1600,10 +1604,8 @@
 ServiceManagementLayer::StartSMLServer()
 {
-    //printf("Ready for CE Signal! (registration done)\n");
     struct timeval selTimeout;
     int32_t running = 1;
     int32_t port, rc, new_sd = 1;
     int32_t desc_ready = 1;
-        //If there is, call the MessageHandler with the Shell_Msg code of -1
     fd_set sockSet, shellSet;
 
@@ -1614,5 +1616,4 @@
         ERROR(1,"Error initializing primary port\n");
 
-    
     while (running) {
         /* Zero socket descriptor vector and set for server sockets */
@@ -1622,35 +1623,28 @@
         
         for(uint16_t k = 0; k < Current_ID; k++){
-        if(CE_List[k].ID_num != -1)
-            FD_SET(CE_List[k].FD, &sockSet);
-    }
-        //printf("k=%d, CID=%d\n", k, CE_List[k].FD);
+            if(CE_List[k].ID_num != -1)
+                FD_SET(CE_List[k].FD, &sockSet);
+        }
 
         /* Timeout specification */
         /* This must be reset every time select() is called */
-        selTimeout.tv_sec = 0;       /* timeout (secs.) */
-        selTimeout.tv_usec = 0;            /* 0 microseconds */
-    //Changed both to zero so that select will check messages from the shell instead of blocking
-    //when there is no command from the CE's to be processed
-
-        //Check if there is a message on the socket waiting to be read
-    rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout); 
-        //printf("rc=%d\n", rc);
-        if(rc == 0){
-            //LOG("No echo requests for %i secs...Server still alive\n", 10);
-    
+        selTimeout.tv_sec = 0;      /* timeout (secs.) */
+        selTimeout.tv_usec = 0;     /* 0 microseconds */
+
+        /* Changed both to zero so that select will check messages from the shell
+         * instead of blocking when there is no command from the CE's to be processed */
+
+        /* Check ifthere is a message on the socket waiting to be read */
+        rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout); 
+        if(rc == 0) {
             FD_ZERO(&shellSet);
             FD_SET(shellSocketFD, &shellSet);
             selTimeout.tv_sec = 0;
             selTimeout.tv_usec = 0;
-            //Check if there is a message on the shell socket ready to be processed
+            /* Check ifthere is a message on the shell socket ready to be processed */
             select(shellSocketFD + 1, &shellSet, NULL, NULL, &selTimeout);
-            //printf("rc2=%d\n", rc2);
-        //If there is, call the MessageHandler with the Shell_Msg code of -1
-        if(FD_ISSET(shellSocketFD, &shellSet)){
-        //printf("shell_msg, %d\n", rc2);
-            MessageHandler(-1);}
-    }
-        else { 
+            if(FD_ISSET(shellSocketFD, &shellSet)){
+                MessageHandler(-1);}
+        } else { 
             desc_ready = rc;
             for(port = 0; port <= maxDescriptor && desc_ready > 0; port++) {
@@ -1658,7 +1652,7 @@
                     desc_ready -= 1;
 
-                    //Check if request is new or on an existing open descriptor
+                    /* Check ifrequest is new or on an existing open descriptor */
                     if(port == cogEngSrv) { 
-            //If new, assign it a descriptor and give it an ID
+                        /* If new, assign it a descriptor and give it an ID */
                         new_sd = AcceptTCPConnection(port);
              
@@ -1667,23 +1661,22 @@
 
                         CE_List[Current_ID].FD = new_sd;
-            CE_List[Current_ID].ID_num = Current_ID;
+                        CE_List[Current_ID].ID_num = Current_ID;
                         MessageHandler(Current_ID);
-            Current_ID++;
+                        Current_ID++;
     
-            FD_SET(new_sd,&sockSet);
+                        FD_SET(new_sd,&sockSet);
                         if(new_sd > maxDescriptor) 
                            maxDescriptor = new_sd;
-                    } 
-                    else {
-            //If old, figure out which ID it coresponds to and handle it accordingly
-            for(uint16_t z = 0; z < Current_ID; z++)
-            {
-                if(CE_List[z].FD == port){
-                    MessageHandler(z);}
-            }
+                    } else {
+                        /* If old, figure out which ID it coresponds to and handle it accordingly */
+                        for(size_t z = 0; z < Current_ID; z++) {
+                            if(CE_List[z].FD == port) {
+                                MessageHandler(z);
+                            }
+                        }
                     }
                 }
             }
-    }
+        }
     }        
 
@@ -1691,5 +1684,5 @@
     close(cogEngSrv);
 
-    //delete &cogEngSrv;
     return;
 }
+
