diff --git a/libIRDB/src/core/decode_cs.cpp b/libIRDB/src/core/decode_cs.cpp
index 6adb095b4187d9191d18826eb085f3457d5fb3cf..8abf6637bdbe166cc0f002b2a1ca8dbc9ae851e7 100644
--- a/libIRDB/src/core/decode_cs.cpp
+++ b/libIRDB/src/core/decode_cs.cpp
@@ -18,7 +18,6 @@ DecodedInstructionCapstone_t::CapstoneHandle_t* DecodedInstructionCapstone_t::cs
 
 DecodedInstructionCapstone_t::CapstoneHandle_t::CapstoneHandle_t(FileIR_t* firp)
 {
-
 	const auto width=FileIR_t::GetArchitectureBitWidth();
 	const auto mode = (width==64) ? CS_MODE_64: CS_MODE_32;
 	auto err = cs_open(CS_ARCH_X86, mode,  &handle);
diff --git a/libIRDB/src/core/fileir.cpp b/libIRDB/src/core/fileir.cpp
index 5225664cbdb3ab4271752ef0e624343e305ec019..787fb0c554d9eaabc194304a0d1bc43b4271ee4b 100644
--- a/libIRDB/src/core/fileir.cpp
+++ b/libIRDB/src/core/fileir.cpp
@@ -752,7 +752,7 @@ void FileIR_t::WriteToDB()
 		}
 	}
 	dbintr->IssueQuery(q);
-
+	
 
 // write out functions 
 	auto withHeader=true;
@@ -777,7 +777,6 @@ void FileIR_t::WriteToDB()
 	}
 	W_addrs.complete();
 
-
 // write out instructions
 
 	pqxx::tablewriter W(pqIntr->GetTransaction(),fileptr->instruction_table_name);
@@ -823,7 +822,6 @@ void FileIR_t::WriteToDB()
 			}
 		}
 
-
 		const auto &insn_values=(*i)->WriteToDB(fileptr,j);
 		W << insn_values;
 
@@ -831,7 +829,6 @@ void FileIR_t::WriteToDB()
 	W.complete();
 
 
-
 // icfs 
 	for (ICFSSet_t::iterator it = GetAllICFS().begin(); it != GetAllICFS().end(); ++it)
 	{
diff --git a/libIRDB/src/core/variantid.cpp b/libIRDB/src/core/variantid.cpp
index 1de34b5f1275a0a1340d28d586af4533326aad69..ac45b0d0e44aecd4baede4bce38b358b324a4ca4 100644
--- a/libIRDB/src/core/variantid.cpp
+++ b/libIRDB/src/core/variantid.cpp
@@ -63,8 +63,7 @@ VariantID_t::VariantID_t(db_id_t pid) : BaseObj_t(NULL)
 	q+=to_string(pid);
 	q+=";";
 
-
-	try 
+       	try 
 	{
 		BaseObj_t::dbintr->IssueQuery(q);
 	}
@@ -76,7 +75,7 @@ VariantID_t::VariantID_t(db_id_t pid) : BaseObj_t(NULL)
 
 		throw DatabaseError_t(DatabaseError_t::VariantTableNotRegistered); 
 	};
-
+	
 	if(BaseObj_t::dbintr->IsDone())
 		throw DatabaseError_t(DatabaseError_t::VariantNotInDatabase); 
 
diff --git a/libIRDB/src/util/IRDB_Objects.cpp b/libIRDB/src/util/IRDB_Objects.cpp
index a920ff493696c8685e19296cfd7bc9e4f84cf62c..8e7228a2536766c60e8fc2ace0bd5936a6eb6a4e 100644
--- a/libIRDB/src/util/IRDB_Objects.cpp
+++ b/libIRDB/src/util/IRDB_Objects.cpp
@@ -43,6 +43,8 @@ shared_ptr<FileIR_t> IRDBObjects_t::AddFileIR(db_id_t variant_id, db_id_t file_i
                 it->second.second = make_shared<FileIR_t>(the_variant, the_file);
                 assert(it->second.second != NULL);
             }
+	    // make sure static variable is set in the calling module -- IMPORTANT
+	    (it->second.second)->SetArchitecture();
             return it->second.second;
         }
 }
@@ -61,7 +63,9 @@ int IRDBObjects_t::WriteBackFileIR(db_id_t file_id)
             try
             {
                 cout<<"Writing changes for "<<the_file->GetURL()<<endl;
-                (it->second.second)->WriteToDB();
+		// make sure static variable is set in the calling module -- IMPORTANT
+                (it->second.second)->SetArchitecture();
+	        (it->second.second)->WriteToDB();
             }
             catch (DatabaseError_t pnide)
             {
@@ -123,14 +127,15 @@ bool IRDBObjects_t::FilesAlreadyPresent(set<File_t*> the_files)
 
 shared_ptr<VariantID_t> IRDBObjects_t::AddVariant(db_id_t variant_id)
 {
-        map<db_id_t, shared_ptr<VariantID_t>>::iterator var_it = variant_map.find(variant_id);        
+        map<db_id_t, shared_ptr<VariantID_t>>::iterator var_it = variant_map.find(variant_id);      
+
         if(var_it != variant_map.end())
         {
             return var_it->second;
         }
-    
+
         shared_ptr<VariantID_t> the_variant = make_shared<VariantID_t>(variant_id);      
-        
+
         assert(the_variant->IsRegistered()==true);
         // disallow variants that share shallow copies to both be read in
         // to prevent desynchronization. 
@@ -138,7 +143,7 @@ shared_ptr<VariantID_t> IRDBObjects_t::AddVariant(db_id_t variant_id)
         
         pair<db_id_t, shared_ptr<VariantID_t>> var_pair = make_pair(variant_id, the_variant);
         variant_map.insert(var_pair);
-        
+
         // add files
         for(set<File_t*>::iterator it=the_variant->GetFiles().begin();
             it!=the_variant->GetFiles().end();
@@ -242,7 +247,7 @@ int IRDBObjects_t::DeleteVariant(db_id_t variant_id)
 int IRDBObjects_t::WriteBackAll(void)
 {
         int ret_status = 0;
-    
+   	cout << "Writing file IRs" << endl; 
         // Write back FileIRs
         for(map<db_id_t, pair<shared_ptr<File_t>, shared_ptr<FileIR_t>>>::iterator
                 file_it = file_IR_map.begin(); 
@@ -256,7 +261,7 @@ int IRDBObjects_t::WriteBackAll(void)
                 ret_status = -1;
             }
         }
-    
+
         // Write back Variants
         for(map<db_id_t, shared_ptr<VariantID_t>>::iterator
                 var_it = variant_map.begin(); 
diff --git a/libIRDB/test/fill_in_cfg.cpp b/libIRDB/test/fill_in_cfg.cpp
index 5902eb56f1b4d2a051e48c84a13616d77e007ddf..6c451d5b4314b72e06ff3ef6a82ffd966af1fc29 100644
--- a/libIRDB/test/fill_in_cfg.cpp
+++ b/libIRDB/test/fill_in_cfg.cpp
@@ -614,6 +614,9 @@ int PopulateCFG::ExecuteStep(IRDBObjects_t *irdb_objects)
     try 
 	{
 		pqxx_interface = irdb_objects->GetDBInterface();
+		// now set the DB interface for THIS PLUGIN LIBRARY -- VERY IMPORTANT
+		BaseObj_t::SetInterface(pqxx_interface);	
+
 		shared_ptr<VariantID_t> variant = irdb_objects->AddVariant(variant_id);
 		for(File_t* file : variant->GetFiles())
 		{
diff --git a/tools/thanos/thanos.cpp b/tools/thanos/thanos.cpp
index f12462edf7bf666c19cd210dc7ed6752b444ad0e..b697b95c9355207059ce159e91cb59965ccd64ae 100644
--- a/tools/thanos/thanos.cpp
+++ b/tools/thanos/thanos.cpp
@@ -18,9 +18,12 @@ using namespace Transform_SDK;
 
 #define MAX_BUF 1024
 
-int execute_step(int argc, char* argv[], bool step_optional, 
+enum class Mode { DEBUG, VERBOSE, DEFAULT };
+
+int execute_step(int argc, char* argv[], bool step_optional, Mode exec_mode, 
                  IRDBObjects_t* shared_objects, TransformStep_t* the_step);
 
+
 // The toolchain driver script ps_analyze.sh communicates
 // with this program via two pipes. This allows DB objects to be held
 // in memory and shared across steps without rewriting the entire ps_analyze.sh
@@ -60,12 +63,9 @@ int main(int argc, char *argv[])
     }
    
     // Main loop where ps_analyze communicates with thanos.exe
-    // to execute steps that conform to the Transform Step SDK.
-    enum class Mode { DEBUG, VERBOSE, DEFAULT };
-    
-    Mode exec_mode = Mode::DEFAULT;
-    IRDBObjects_t* shared_objects = new IRDBObjects_t();
-    
+    // to execute steps that conform to the Transform Step SDK.    
+    Mode exec_mode = Mode::DEBUG;
+    IRDBObjects_t* shared_objects = new IRDBObjects_t();    
     while (true) 
     {
         if((num_bytes_read = read(in_pipe_fd, buf, MAX_BUF)) > 0)
@@ -157,8 +157,7 @@ int main(int argc, char *argv[])
                                 }
                                 int step_retval = 0;
 
-				if(exec_mode == Mode::DEFAULT)
-				    step_retval = execute_step(argc, argv, step_optional, shared_objects, the_step);
+				step_retval = execute_step(argc, argv, step_optional, exec_mode, shared_objects, the_step);
                                 delete the_step;
 				free(argv);
                                 dlclose(dlhdl);
@@ -200,7 +199,7 @@ int main(int argc, char *argv[])
 }
 
 
-int execute_step(int argc, char* argv[], bool step_optional, 
+int execute_step(int argc, char* argv[], bool step_optional, Mode exec_mode, 
                  IRDBObjects_t* shared_objects, TransformStep_t* the_step)
 {
     int parse_retval = the_step->ParseArgs(argc, argv);
@@ -209,9 +208,68 @@ int execute_step(int argc, char* argv[], bool step_optional,
         return parse_retval;
     }
     
+    pqxxDB_t* pqxx_interface = shared_objects->GetDBInterface();
+    if(step_optional)
+    {
+        int error = shared_objects->WriteBackAll();
+        if(error)
+        {
+            return -1; // the failure must be from a critical step, abort
+        }
+        else
+        {
+            // commit changes (in case this step fails) and reset interface
+            pqxx_interface->Commit();
+            pqxx_interface = shared_objects->ResetDBInterface();
+        }
+    }
+
+    int step_error = the_step->ExecuteStep(shared_objects);
+
+    if(step_error)
+    {
+        if(step_optional)
+        {
+            // delete all shared items without writing
+            // next step will have to get the last "good" version from DB
+            shared_objects->DeleteAll();
+        }
+        else
+        {
+            return -1; // critical step failed, abort
+        }
+    }
+    
     if(step_optional)
     {
-        shared_objects->WriteBackAll();        
+        // write changes to DB to see if it succeeds
+        int error = shared_objects->WriteBackAll();
+        if(error)
+        {
+            // abort changes by resetting DB interface
+            pqxx_interface = shared_objects->ResetDBInterface();
+        }
+        else if(exec_mode == Mode::DEBUG)
+        {
+            // commit changes (in case next step fails) and reset interface 
+            pqxx_interface->Commit();
+            pqxx_interface = shared_objects->ResetDBInterface();
+        }
+    }
+    else if(exec_mode == Mode::DEBUG)
+    {
+        // write changes to DB in case next step fails
+        int error = shared_objects->WriteBackAll();
+        if(error)
+        {
+            return -1; // critical step failed, abort
+        }
+        else
+        {
+            // commit changes (in case next step fails) and reset interface 
+            pqxx_interface->Commit();
+            pqxx_interface = shared_objects->ResetDBInterface();
+        }
     }
     
     return 12;