Index: vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp
===================================================================
--- vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 448)
+++ vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 461)
@@ -57,9 +57,8 @@
 
 
-typedef struct services_s *services_DB;
-typedef struct data_s *data_DB;
-
 using namespace std;
 
+
+/* Internal structs used to keep track of sqlite database information. */
 struct services_s {
     string filename;
@@ -78,10 +77,23 @@
 };
 
-services_DB _services_DB;
-data_DB _data_DB;
+typedef struct services_s *services_DB_t;
+typedef struct data_s *data_DB_t;
+
+/* Global tracking of the services and parameters that this instance of SML is
+ * aware of. */
+services_DB_t services_DB;
+data_DB_t data_DB;
+
+/* The filename of the SML configuration, used if the SML is told to reload it's
+ * configuration. */
 string _SML_Config;
-bool shellFound;
-
-/* Callback function used internally by some of the SQLite3 commands */
+
+/* Keeps track of whether or not the 'shell' component is used by the active
+ * mission. */
+bool shellUsed;
+
+
+/* Callback function used internally by some of the SQLite3 commands for debug
+ * output. Code provided by sqlite documentation. */
 int32_t 
 callback(void *notUsed, int32_t argc, char **argv, char **azColName)
@@ -94,4 +106,5 @@
     return 0;
 }
+
 
 /* Useful for spotchecking what's in the database */
@@ -101,16 +114,16 @@
     /*
     LOG("\n\n\n");
-    _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(";");
+    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(";");
 
     char *errorMsg;
-    int32_t rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg);
+    int32_t rc = sqlite3_exec(data_DB->db, data_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", _data_DB->filename, _data_DB->tablename);
+    LOG("database %s, table %s:\n", data_DB->filename, data_DB->tablename);
     LOG("\n\n\n");
     */
@@ -137,29 +150,29 @@
     int32_t rc;         /* sqlite command return code */
 
-    _services_DB->command = "drop table ";
-    _services_DB->command.append(_services_DB->tablename);
-    rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg);
+    services_DB->command = "drop table ";
+    services_DB->command.append(services_DB->tablename);
+    rc = sqlite3_exec(services_DB->db, services_DB->command.c_str(), callback, 0, &errorMsg);
     if((rc != SQLITE_OK) && (rc != 101))
         WARNING("ServiceManagementLayer::Destructor services 'drop table' error: %s\n", errorMsg);
 
-    _services_DB->command = "vacuum";
-    rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg);
+    services_DB->command = "vacuum";
+    rc = sqlite3_exec(services_DB->db, services_DB->command.c_str(), callback, 0, &errorMsg);
     if((rc != SQLITE_OK) && (rc != 101))
         WARNING("ServiceManagementLayer::Destructor services 'vacuum' error: %s\n", errorMsg);
 
-    free(_services_DB);
-
-    _data_DB->command = "drop table ";
-    _data_DB->command.append(_data_DB->tablename);
-    rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg);
+    free(services_DB);
+
+    data_DB->command = "drop table ";
+    data_DB->command.append(data_DB->tablename);
+    rc = sqlite3_exec(data_DB->db, data_DB->command.c_str(), callback, 0, &errorMsg);
     if((rc != SQLITE_OK) && (rc != 101))
         WARNING("ServiceManagementLayer::Destructor data 'drop table' error: %s\n", errorMsg);
 
-    _data_DB->command = "vacuum";
-    rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg);
+    data_DB->command = "vacuum";
+    rc = sqlite3_exec(data_DB->db, data_DB->command.c_str(), callback, 0, &errorMsg);
     if((rc != SQLITE_OK) && (rc != 101))
         WARNING("ServiceManagementLayer::Destructor data 'vacuum' error: %s\n", errorMsg);
 
-    free(_data_DB);
+    free(data_DB);
 }
 
@@ -204,18 +217,18 @@
     int32_t rc;             /* sqlite command return code */
 
-    _services_DB = new services_s;
-    _services_DB->filename="Services_Table";
-    sqlite3_open(_services_DB->filename.c_str(), &(_services_DB->db));
+    services_DB = new services_s;
+    services_DB->filename="Services_Table";
+    sqlite3_open(services_DB->filename.c_str(), &(services_DB->db));
 
     char *cols[] = {(char *)"ID_Num", (char *)"Service_Name"};
 
-    _services_DB->tablename="Services";
+    services_DB->tablename="Services";
 
     /* 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 ifEXISTS Services;";     
-
-    rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail);
+    services_DB->command = "DROP TABLE ifEXISTS Services;";     
+
+    rc = sqlite3_prepare_v2(services_DB->db, services_DB->command.c_str(), 128, &ppStmt, &pzTail);
     if((rc != SQLITE_OK) && (rc != 101))
         WARNING("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc);
@@ -225,17 +238,17 @@
         WARNING("ServiceManagementLayer::CreateServicesDB 'step' error\n");
 
-    _services_DB->num_columns = 2;
+    services_DB->num_columns = 2;
 
     /* Generate command */
-    _services_DB->command="CREATE TABLE ";
-    _services_DB->command.append(_services_DB->tablename);
-    _services_DB->command.append("(");
-    _services_DB->command.append(cols[0]);
-    _services_DB->command.append(" INT, ");
-    _services_DB->command.append(cols[1]);
-    _services_DB->command.append(" TEXT);");
+    services_DB->command="CREATE TABLE ";
+    services_DB->command.append(services_DB->tablename);
+    services_DB->command.append("(");
+    services_DB->command.append(cols[0]);
+    services_DB->command.append(" INT, ");
+    services_DB->command.append(cols[1]);
+    services_DB->command.append(" TEXT);");
 
     /* Execute create table command */
-    rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail);
+    rc = sqlite3_prepare_v2(services_DB->db, services_DB->command.c_str(), 128, &ppStmt, &pzTail);
     if((rc != SQLITE_OK) && (rc != 101))
         WARNING("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc);
@@ -259,15 +272,15 @@
     int32_t rc;             /* sqlite command return code */
 
-    _data_DB = new data_s;
-
-    _data_DB->filename="Data_Table";
-    sqlite3_open(_data_DB->filename.c_str(), &(_data_DB->db));
+    data_DB = new data_s;
+
+    data_DB->filename="Data_Table";
+    sqlite3_open(data_DB->filename.c_str(), &(data_DB->db));
 
     char *cols[] = {(char *)"Tag", (char *)"Data"};
 
-    _data_DB->tablename = "Data";
-    _data_DB->command = "DROP TABLE ifEXISTS Data;";     
-
-    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail);
+    data_DB->tablename = "Data";
+    data_DB->command = "DROP TABLE ifEXISTS Data;";     
+
+    rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), 128, &ppStmt, &pzTail);
     if((rc != SQLITE_OK) && (rc != 101))
         WARNING("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc);
@@ -277,19 +290,19 @@
         WARNING("ServiceManagementLayer::CreateDataDB 'step' error\n");
 
-    _data_DB->num_columns = 2;
+    data_DB->num_columns = 2;
 
     /* Generate command */
-    _data_DB->command = "CREATE TABLE ";
-    _data_DB->command.append(_data_DB->tablename);
-    _data_DB->command.append("(");
-    _data_DB->command.append(cols[0]);
+    data_DB->command = "CREATE TABLE ";
+    data_DB->command.append(data_DB->tablename);
+    data_DB->command.append("(");
+    data_DB->command.append(cols[0]);
 
     /* First column is the name of the data (corresponding to the name of the output/input pair)
      * It is the primary key so any subsequent data with the same name will replace the row. */
-    _data_DB->command.append(" TEXT PRIMARY KEY ON CONFLICT REPLACE, ");
-    _data_DB->command.append(cols[1]);
-    _data_DB->command.append(" TEXT);");
-
-    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail);
+    data_DB->command.append(" TEXT PRIMARY KEY ON CONFLICT REPLACE, ");
+    data_DB->command.append(cols[1]);
+    data_DB->command.append(" TEXT);");
+
+    rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), 128, &ppStmt, &pzTail);
     if((rc != SQLITE_OK) && (rc != 101))
         WARNING("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc);
@@ -574,12 +587,12 @@
 
     /* Generate command */
-    _services_DB->command = "insert into ";
-    _services_DB->command.append(_services_DB->tablename); 
-    _services_DB->command.append(" (");
-    _services_DB->command.append(cols[0]);
-    _services_DB->command.append(", ");
-    _services_DB->command.append(cols[1]);
-    _services_DB->command.append(") ");
-    _services_DB->command.append(" values(");
+    services_DB->command = "insert into ";
+    services_DB->command.append(services_DB->tablename); 
+    services_DB->command.append(" (");
+    services_DB->command.append(cols[0]);
+    services_DB->command.append(", ");
+    services_DB->command.append(cols[1]);
+    services_DB->command.append(") ");
+    services_DB->command.append(" values(");
 
     char temp[3];
@@ -587,12 +600,12 @@
     sprintf(temp, "%d", ID);
 
-    _services_DB->command.append(temp);
-    _services_DB->command.append(", '");
-    _services_DB->command.append(buffer);
-    _services_DB->command.append("');");
+    services_DB->command.append(temp);
+    services_DB->command.append(", '");
+    services_DB->command.append(buffer);
+    services_DB->command.append("');");
     
     /* Execute add command */
     char *errorMsg;
-    int rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg);
+    int rc = sqlite3_exec(services_DB->db, services_DB->command.c_str(), callback, 0, &errorMsg);
     if((rc != SQLITE_OK) && (rc != 101))
         WARNING("ServiceManagementLayer::RecieveServices DB Error %s\n", errorMsg);
@@ -633,14 +646,14 @@
                 /* ifit is a service, search the database of registered services to find 
                  * the ID of the component that registered it */
-                _services_DB->command="select ";
-                _services_DB->command.append(_services_DB->tablename);
-                _services_DB->command.append(".* from ");
-                _services_DB->command.append( _services_DB->tablename);
-                _services_DB->command.append(" where Service_Name=='");
-                _services_DB->command.append(miss[activeMission].services[i].name);
-                _services_DB->command.append("';");
+                services_DB->command="select ";
+                services_DB->command.append(services_DB->tablename);
+                services_DB->command.append(".* from ");
+                services_DB->command.append( services_DB->tablename);
+                services_DB->command.append(" where Service_Name=='");
+                services_DB->command.append(miss[activeMission].services[i].name);
+                services_DB->command.append("';");
     
                 sqlite3_stmt * pStatement;
-                int32_t rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), \
+                int32_t rc = sqlite3_prepare_v2(services_DB->db, services_DB->command.c_str(), \
                         -1, &pStatement, NULL);
                 if(rc == SQLITE_OK) { 
@@ -655,5 +668,5 @@
                 } else {
                     WARNING("services_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                            rc, _services_DB->command.c_str());
+                            rc, services_DB->command.c_str());
                 }
 
@@ -691,5 +704,5 @@
    /* Send a message directly to the shell */
    if(miss[activeMission].services[sourceID].name.find("shell") != string::npos) {
-       shellFound=true;
+       shellUsed=true;
 
        int32_t k = 0;
@@ -702,14 +715,14 @@
        for(int32_t t = 0; t < k; t++) {
            memset(buffer, 0 , 256);
-           _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].input[t]);
-           _data_DB->command.append("';");
+           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].input[t]);
+           data_DB->command.append("';");
            sqlite3_stmt * pStatement;
 
-           int32_t rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), \
+           int32_t rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), \
                    -1, &pStatement, NULL);
            if(rc == SQLITE_OK) { 
@@ -717,5 +730,5 @@
                    data=((const char*) sqlite3_column_text(pStatement, 1)); 
                else {
-                   LOG("3data_DB:: Data not yet in DB., %s\n", _data_DB->command.c_str());
+                   LOG("3data_DB:: Data not yet in DB., %s\n", data_DB->command.c_str());
                    rc = 31337;
                }
@@ -723,5 +736,5 @@
            else {
                WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                       rc,_data_DB->command.c_str());
+                       rc,data_DB->command.c_str());
            }
 
@@ -768,5 +781,5 @@
 ServiceManagementLayer::PerformActiveMission()
 {
-    shellFound = false;
+    shellUsed = false;
     std::string data_param;
     std::string data_obsv;
@@ -797,23 +810,23 @@
         memset(buffer1, 0, 256);
         ReadMessage(shellSocketFD, buffer1);
-        _data_DB->command="insert into ";
-        _data_DB->command.append(_data_DB->tablename); 
-        _data_DB->command.append(" (");
-        _data_DB->command.append(cols[0]);
-        _data_DB->command.append(", ");
-        _data_DB->command.append(cols[1]);
-        _data_DB->command.append(") ");
+        data_DB->command="insert into ";
+        data_DB->command.append(data_DB->tablename); 
+        data_DB->command.append(" (");
+        data_DB->command.append(cols[0]);
+        data_DB->command.append(", ");
+        data_DB->command.append(cols[1]);
+        data_DB->command.append(") ");
 
         memset(buffer, 0, 256);
         ReadMessage(shellSocketFD, buffer);
-        _data_DB->command.append(" values('");
-        _data_DB->command.append(buffer1);
-        _data_DB->command.append("', '1@");
-        _data_DB->command.append(buffer1);
-        _data_DB->command.append("@");
-        _data_DB->command.append(buffer);
-        _data_DB->command.append("');");
-
-        rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg);
+        data_DB->command.append(" values('");
+        data_DB->command.append(buffer1);
+        data_DB->command.append("', '1@");
+        data_DB->command.append(buffer1);
+        data_DB->command.append("@");
+        data_DB->command.append(buffer);
+        data_DB->command.append("');");
+
+        rc = sqlite3_exec(data_DB->db, data_DB->command.c_str(), callback, 0, &errorMsg);
         if((rc != SQLITE_OK) && (rc != 101))
            WARNING("SQL error: %s\n", errorMsg);
@@ -830,14 +843,14 @@
                     input = miss[activeMission].services[i - numstatements[0] - 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("';");
+                    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(), \
+                    rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), \
                             -1, &pStatement, NULL);
                     if(rc == SQLITE_OK) { 
@@ -850,5 +863,5 @@
                     } else {
                         WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                                rc,_data_DB->command.c_str());
+                                rc,data_DB->command.c_str());
                     }
 
@@ -865,14 +878,14 @@
             if(miss[activeMission].services[i].output[t].find(">") != string::npos) {
                 std::string data2;
-                _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[i].output[t].erase(0, 1));
-                _data_DB->command.append("';");
+                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[i].output[t].erase(0, 1));
+                data_DB->command.append("';");
                 sqlite3_stmt *pStatement;
 
-                rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), \
+                rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), \
                         -1, &pStatement, NULL);
                 if(rc == SQLITE_OK) { 
@@ -885,5 +898,5 @@
                 } else {
                     WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                            rc, _data_DB->command.c_str());
+                            rc, data_DB->command.c_str());
                 }
 
@@ -907,14 +920,14 @@
                             if(!miss[activeMission].services[k].output[t].empty()) {
                                 input = miss[activeMission].services[k - numstatements[1] - 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("';");
+                                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(), \
+                                rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), \
                                         -1, &pStatement, NULL);
                                 if(rc == SQLITE_OK) { 
@@ -927,5 +940,5 @@
                                 } else {
                                     WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                                            rc,_data_DB->command.c_str());
+                                            rc,data_DB->command.c_str());
                                 }
 
@@ -941,14 +954,14 @@
                         if(miss[activeMission].services[k].output[t].find(">") != string::npos) {
                             std::string data2;
-                            _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[k].output[t].erase(0, 1));
-                            _data_DB->command.append("';");
+                            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[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(), \
+                            rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), \
                                     -1, &pStatement, NULL);
                             if(rc == SQLITE_OK) { 
@@ -961,5 +974,5 @@
                             } else {
                                 WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                                        rc, _data_DB->command.c_str());
+                                        rc, data_DB->command.c_str());
                             }
 
@@ -983,15 +996,15 @@
                                             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("';");
+                                            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);
+                                            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)
@@ -1003,5 +1016,5 @@
                                             } else {
                                                 WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                                                        rc, _data_DB->command.c_str());
+                                                        rc, data_DB->command.c_str());
                                             }
 
@@ -1017,14 +1030,14 @@
                                     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("';");
+                                        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);
+                                        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)
@@ -1036,5 +1049,5 @@
                                         } else {
                                             WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                                                    rc, _data_DB->command.c_str());
+                                                    rc, data_DB->command.c_str());
                                         }
 
@@ -1079,24 +1092,24 @@
                                             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("';");
+                                                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);
+                                                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());
+                                                        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());
+                                                            rc, data_DB->command.c_str());
                                                 }
 
@@ -1139,14 +1152,14 @@
                                 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("';");
+                                    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);
+                                    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)
@@ -1158,5 +1171,5 @@
                                     } else {
                                         WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                                                rc, _data_DB->command.c_str());
+                                                rc, data_DB->command.c_str());
                                     }
 
@@ -1199,14 +1212,14 @@
                     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("';");
+                        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);
+                        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)
@@ -1218,5 +1231,5 @@
                         } else {
                             WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \
-                                    rc, _data_DB->command.c_str());
+                                    rc, data_DB->command.c_str());
                         }
 
@@ -1244,5 +1257,5 @@
     data.clear();
 
-    if(!shellFound) {
+    if(!shellUsed) {
         int k = 0;
         while(k < 10 && !miss[activeMission].input[k].empty()) {
@@ -1272,17 +1285,17 @@
 ServiceManagementLayer::ListServices()
 {
-    _services_DB->command="select ";
-    _services_DB->command.append(_services_DB->tablename);
-    _services_DB->command.append(".* from ");
-    _services_DB->command.append(_services_DB->tablename);
-    _services_DB->command.append(";");
+    services_DB->command="select ";
+    services_DB->command.append(services_DB->tablename);
+    services_DB->command.append(".* from ");
+    services_DB->command.append(services_DB->tablename);
+    services_DB->command.append(";");
 
     // Execute print (select all) command
     char *errorMsg;
-    int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &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);
 
-    LOG("database %s, table %s:\n", _services_DB->filename.c_str(), _services_DB->tablename.c_str());
+    LOG("database %s, table %s:\n", services_DB->filename.c_str(), services_DB->tablename.c_str());
 }
 
@@ -1525,21 +1538,21 @@
     memset(buffer, 0, 256);
     ReadMessage(CE_List[ID].FD, buffer); 
-    _services_DB->command="DELETE FROM ";
-    _services_DB->command.append(_services_DB->tablename);
-    _services_DB->command.append(" WHERE ID_Num IN (SELECT ");
+    services_DB->command="DELETE FROM ";
+    services_DB->command.append(services_DB->tablename);
+    services_DB->command.append(" WHERE ID_Num IN (SELECT ");
 
     char tmp[3];
     memset(tmp,0,3);
     sprintf(tmp, "%d", ID);
-    _services_DB->command.append(tmp);
-    _services_DB->command.append(" FROM ");
-    _services_DB->command.append(_services_DB->tablename);
-    _services_DB->command.append(" WHERE Service_Name");
-    _services_DB->command.append("=='");
-    _services_DB->command.append(buffer);
-    _services_DB->command.append("');");
+    services_DB->command.append(tmp);
+    services_DB->command.append(" FROM ");
+    services_DB->command.append(services_DB->tablename);
+    services_DB->command.append(" WHERE Service_Name");
+    services_DB->command.append("=='");
+    services_DB->command.append(buffer);
+    services_DB->command.append("');");
 
     char *errorMsg;
-    int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &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);
@@ -1572,18 +1585,18 @@
 
     //Deregister the services
-    _services_DB->command="DELETE FROM ";
-    _services_DB->command.append(_services_DB->tablename);
-    _services_DB->command.append(" WHERE ");
-    _services_DB->command.append("ID_Num");
-    _services_DB->command.append("==");
+    services_DB->command="DELETE FROM ";
+    services_DB->command.append(services_DB->tablename);
+    services_DB->command.append(" WHERE ");
+    services_DB->command.append("ID_Num");
+    services_DB->command.append("==");
 
     char tmp[3];
     memset(tmp,0,3);
     sprintf(tmp, "%d", ID);
-    _services_DB->command.append(tmp);
-    _services_DB->command.append(";");
+    services_DB->command.append(tmp);
+    services_DB->command.append(";");
 
     char *errorMsg;
-    int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &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);
