From: westcott <westcott>
Date: Thu, 18 Jun 2009 16:05:46 +0000 (+0000)
Subject: fixed some bugs
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=02909d6cae9963ba00dc746969a370fa8ca934fc;p=mothur.git

fixed some bugs
---

diff --git a/aligncommand.cpp b/aligncommand.cpp
index ccfd9bb..064189b 100644
--- a/aligncommand.cpp
+++ b/aligncommand.cpp
@@ -104,9 +104,13 @@ AlignCommand::AlignCommand(string option){
 
 //**********************************************************************************************************************
 
-AlignCommand::~AlignCommand(){			
-	delete templateDB;
-	delete alignment;
+AlignCommand::~AlignCommand(){	
+
+	if (abort == false) {
+		for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
+		delete templateDB;
+		delete alignment;
+	}
 }
 
 //**********************************************************************************************************************
@@ -178,6 +182,7 @@ int AlignCommand::execute(){
 			lines.push_back(new linePair(0, numFastaSeqs));
 			
 			driver(lines[0], alignFileName, reportFileName);
+			
 		}
 		else{
 			vector<int> positions;
@@ -216,6 +221,7 @@ int AlignCommand::execute(){
 				appendReportFiles((reportFileName + toString(processIDS[i]) + ".temp"), reportFileName);
 				remove((reportFileName + toString(processIDS[i]) + ".temp").c_str());
 			}
+			
 		}
 #else
 		ifstream inFASTA;
@@ -262,7 +268,9 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName){
 			Sequence* candidateSeq = new Sequence(inFASTA);
 			report.setCandidate(candidateSeq);
 			
-			Sequence* templateSeq = templateDB->findClosestSequence(candidateSeq);
+			Sequence temp = templateDB->findClosestSequence(candidateSeq);
+			Sequence* templateSeq = &temp;
+			
 			report.setTemplate(templateSeq);
 			report.setSearchParameters(search, templateDB->getSearchScore());
 			
diff --git a/alignment.cpp b/alignment.cpp
index 95e9dc2..d64d8b2 100644
--- a/alignment.cpp
+++ b/alignment.cpp
@@ -87,6 +87,23 @@ void Alignment::traceBack(){			//	This traceback routine is used by the dynamic
 	seqBend = seqB.length() - seqBend - 1;
 
 }
+/**************************************************************************************************/
+
+Alignment::~Alignment(){
+	try {
+		for (int i = 0; i < alignment.size(); i++) {
+			for (int j = (alignment[i].size()-1); j >= 0; j--) {  alignment[i].pop_back();  }
+		}
+	}
+	catch(exception& e) {
+		cout << "Standard Error: " << e.what() << " has occurred in the Alignment class Function ~Alignment. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+		exit(1);
+	}
+	catch(...) {
+		cout << "An unknown error has occurred in the Alignment class function ~Alignment. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+		exit(1);
+	}
+}
 
 /**************************************************************************************************/
 
diff --git a/alignment.hpp b/alignment.hpp
index c033d62..215e4b3 100644
--- a/alignment.hpp
+++ b/alignment.hpp
@@ -23,6 +23,7 @@ class Alignment {
 public:
 	Alignment(int);
 	Alignment();
+	virtual ~Alignment();
 	virtual void align(string, string) = 0;
 	
 //	float getAlignmentScore();
diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp
index abe000f..1627b42 100644
--- a/binsequencecommand.cpp
+++ b/binsequencecommand.cpp
@@ -44,11 +44,6 @@ BinSeqCommand::BinSeqCommand(string option){
 			fastafile = validParameter.validFile(parameters, "fasta", true);
 			if (fastafile == "not found") { cout << "fasta is a required parameter for the bin.seqs command." << endl; abort = true; }
 			else if (fastafile == "not open") { abort = true; }	
-			else { 
-				openInputFile(fastafile, in);
-				fasta = new FastaMap();
-			}
-		
 		
 			//check for optional parameter and set defaults
 			// ...at some point should added some additional type checking...
@@ -82,10 +77,14 @@ BinSeqCommand::BinSeqCommand(string option){
 			groupfile = validParameter.validFile(parameters, "group", true);
 			if (groupfile == "not open") { abort = true; }
 			else if (groupfile == "not found") { groupfile = ""; }
-			else {
-				//read in group map info.
-				groupMap = new GroupMap(groupfile);
-				groupMap->readMap();
+			
+			if (abort == false) { 
+				openInputFile(fastafile, in);
+				fasta = new FastaMap();
+				if (groupfile != "") {
+					groupMap = new GroupMap(groupfile);
+					groupMap->readMap();
+				}
 			}
 	
 		}
@@ -130,17 +129,12 @@ void BinSeqCommand::help(){
 BinSeqCommand::~BinSeqCommand(){
 	//made new in execute
 	if (abort == false) {
-		delete input;
+		delete input;  globaldata->ginput = NULL;
 		delete read;
-		delete list;
-	}
-	
-	//made new in constructor
-	delete fasta;
-	if (groupfile != "") {
-			delete groupMap;
+		globaldata->gListVector = NULL;
+		delete fasta;
+		if (groupfile != "") {  delete groupMap;  globaldata->gGroupmap = NULL; }
 	}
-
 }
 
 //**********************************************************************************************************************
@@ -155,6 +149,8 @@ int BinSeqCommand::execute(){
 		//read fastafile
 		fasta->readFastaFile(in);
 		
+		in.close();
+		
 		//set format to list so input can get listvector
 //		globaldata->setFormat("list");
 		
diff --git a/blastalign.cpp b/blastalign.cpp
index e4d5e8a..cb6abf9 100644
--- a/blastalign.cpp
+++ b/blastalign.cpp
@@ -154,6 +154,7 @@ void BlastAlignment::setPairwiseSeqs(){	//	This method call assigns the blast ge
 		seqAaln += 'Z';							//	again need ot pad the sequences so that they extend to the length
 		seqBaln += 'X';							//	of the template sequence
 	}
+	blastFile.close();
 }
 
 //**************************************************************************************************/
diff --git a/blastdb.cpp b/blastdb.cpp
index 6f4ebcc..e442fa2 100644
--- a/blastdb.cpp
+++ b/blastdb.cpp
@@ -32,7 +32,7 @@ gapOpen(gO), gapExtend(gE), match(m), misMatch(mM) {
 	
 	for(int i=0;i<numSeqs;i++){									//	generating a fasta file with unaligned template
 		unalignedFastaFile << '>' << i << endl;					//	sequences, which will be input to formatdb
-		unalignedFastaFile << templateSequences[i]->getUnaligned() << endl;
+		unalignedFastaFile << templateSequences[i].getUnaligned() << endl;
 	}
 	unalignedFastaFile.close();
 	
@@ -43,10 +43,10 @@ gapOpen(gO), gapExtend(gE), match(m), misMatch(mM) {
 	system(formatdbCommand.c_str());								//	to get the right sequence names, i think. -p F
 																	//	option tells formatdb that seqs are DNA, not prot
 	cout << "DONE." << endl << endl;	cout.flush();
-	emptySequence = new Sequence();
-	emptySequence->setName("no_match");
-	emptySequence->setUnaligned("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
-	emptySequence->setAligned("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+	emptySequence = Sequence();
+	emptySequence.setName("no_match");
+	emptySequence.setUnaligned("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+	emptySequence.setAligned("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
 
 
 }
@@ -54,6 +54,10 @@ gapOpen(gO), gapExtend(gE), match(m), misMatch(mM) {
 /**************************************************************************************************/
 
 BlastDB::~BlastDB(){
+	//for (int i = 0; i < templateSequences.size(); i++) {  delete templateSequences[i];   }
+	//templateSequences.clear();
+	//delete emptySequence;
+	
 	remove(queryFileName.c_str());				//	let's clean stuff up and remove the temp files
 	remove(dbFileName.c_str());					//	let's clean stuff up and remove the temp files
 	remove(blastFileName.c_str());				//	let's clean stuff up and remove the temp files
@@ -61,7 +65,7 @@ BlastDB::~BlastDB(){
 
 /**************************************************************************************************/
 
-Sequence* BlastDB::findClosestSequence(Sequence* candidate){
+Sequence BlastDB::findClosestSequence(Sequence* candidate){
 
 	ofstream queryFile;
 	openOutputFile(queryFileName, queryFile);
@@ -93,6 +97,7 @@ Sequence* BlastDB::findClosestSequence(Sequence* candidate){
 		searchScore = 0.00;
 		return emptySequence;
 	}
+	m8FileHandle.close();
 }
 
 /**************************************************************************************************/
diff --git a/blastdb.hpp b/blastdb.hpp
index dfb2a2c..f0f17f9 100644
--- a/blastdb.hpp
+++ b/blastdb.hpp
@@ -18,7 +18,7 @@ class BlastDB : public Database {
 public:
 	BlastDB(string, float, float, float, float);
 	~BlastDB();
-	Sequence* findClosestSequence(Sequence*);
+	Sequence findClosestSequence(Sequence*);
 
 private:
 	string dbFileName;
@@ -30,7 +30,7 @@ private:
 	float gapExtend;
 	float match;
 	float misMatch;
-	Sequence* emptySequence;
+	Sequence emptySequence;
 	GlobalData* globaldata;
 };
 
diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp
index 5e7c0c6..a94954a 100644
--- a/bootstrapsharedcommand.cpp
+++ b/bootstrapsharedcommand.cpp
@@ -179,9 +179,10 @@ void BootSharedCommand::help(){
 BootSharedCommand::~BootSharedCommand(){
 	//made new in execute
 	if (abort == false) {
-		delete input;
+		delete input; globaldata->ginput = NULL;
 		delete read;
 		delete util;
+		globaldata->gorder = NULL;
 	}
 }
 
diff --git a/calculator.h b/calculator.h
index 8b21f70..5dc0812 100644
--- a/calculator.h
+++ b/calculator.h
@@ -21,6 +21,7 @@ class Calculator {
 
 public:
 	Calculator(){};
+	virtual ~Calculator(){};
 	Calculator(string n, int c, bool m) : name(n), cols(c), multiple(m) {};
 	virtual EstOutput getValues(SAbundVector*) = 0;	
 	virtual EstOutput getValues(vector<SharedRAbundVector*>) = 0;
diff --git a/clustercommand.cpp b/clustercommand.cpp
index 4db95b4..eeba407 100644
--- a/clustercommand.cpp
+++ b/clustercommand.cpp
@@ -120,8 +120,10 @@ void ClusterCommand::help(){
 //**********************************************************************************************************************
 
 ClusterCommand::~ClusterCommand(){
-	delete cluster;
-	delete rabund;
+	if (abort == false) {
+		delete cluster;
+		delete rabund;
+	}
 }
 
 //**********************************************************************************************************************
@@ -177,6 +179,10 @@ int ClusterCommand::execute(){
 		globaldata->setNameFile("");
 		globaldata->setFormat("list");
 		
+		sabundFile.close();
+		rabundFile.close();
+		listFile.close();
+		
 		return 0;
 	}
 	catch(exception& e) {
diff --git a/collectcommand.cpp b/collectcommand.cpp
index 2dd843f..c65080f 100644
--- a/collectcommand.cpp
+++ b/collectcommand.cpp
@@ -195,11 +195,13 @@ void CollectCommand::help(){
 //**********************************************************************************************************************
 
 CollectCommand::~CollectCommand(){
-	delete order;
-	delete input;
-	delete cCurve;
-	delete read;
-	delete validCalculator;
+	if (abort == false) {
+		//delete order;
+		delete input;  globaldata->ginput = NULL;
+		delete read;
+		delete validCalculator;
+		globaldata->gorder = NULL;
+	}
 }
 
 //**********************************************************************************************************************
@@ -252,7 +254,7 @@ int CollectCommand::execute(){
 				userLabels.erase(lastOrder->getLabel());
 			}
 			
-			if (count != 1) { delete lastOrder; }
+			if (count != 1) { delete lastOrder;  }
 			lastOrder = order;			
 			order = (input->getOrderVector());
 			count++;
diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp
index 6127c2d..86d5ffc 100644
--- a/collectsharedcommand.cpp
+++ b/collectsharedcommand.cpp
@@ -117,7 +117,7 @@ CollectSharedCommand::CollectSharedCommand(string option){
 			if (abort == false) {
 			
 				string fileNameRoot = getRootName(globaldata->inputFileName);
-//				format = globaldata->getFormat();
+				format = globaldata->getFormat();
 				int i;
 				
 				validCalculator = new ValidCalculators();
@@ -214,12 +214,13 @@ void CollectSharedCommand::help(){
 //**********************************************************************************************************************
 
 CollectSharedCommand::~CollectSharedCommand(){
-	delete order;
-	delete input;
-	delete cCurve;
-	delete read;
-	delete util;
-	delete validCalculator;
+	if (abort == false) {
+		delete input; globaldata->ginput = NULL;
+		delete read;
+		delete util;
+		delete validCalculator;
+		globaldata->gorder = NULL;
+	}
 }
 
 //**********************************************************************************************************************
diff --git a/command.hpp b/command.hpp
index 27355dd..1dd5e87 100644
--- a/command.hpp
+++ b/command.hpp
@@ -18,9 +18,11 @@
 #include "validparameter.h"
 
 class Command {
+	
 	public:
 		virtual int execute() = 0;
 		virtual void help() = 0;
+		virtual ~Command() { }
 };
 
 #endif
diff --git a/database.cpp b/database.cpp
index f849146..852e2d2 100644
--- a/database.cpp
+++ b/database.cpp
@@ -41,7 +41,7 @@ Database::Database(string fastaFileName){		//	This assumes that the template dat
 				aligned += letter;
 			}
 		}
-		templateSequences[i] = new Sequence(seqName, aligned);
+		templateSequences[i] = Sequence(seqName, aligned);
 		fastaFile.putback(letter);
 	}
 	
@@ -51,6 +51,24 @@ Database::Database(string fastaFileName){		//	This assumes that the template dat
 	cout << "DONE." << endl;	cout.flush();
 
 }
+/**************************************************************************************************/
+
+Database::~Database(){														
+	try {
+		
+		//for (int i = 0; i < templateSequences.size(); i++) {  delete templateSequences[i];    }
+		templateSequences.clear();
+
+	}
+	catch(exception& e) {
+		cout << "Standard Error: " << e.what() << " has occurred in the Database class Function ~Database. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+		exit(1);
+	}
+	catch(...) {
+		cout << "An unknown error has occurred in the Database class function ~Database. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+		exit(1);
+	}
+}
 
 /**************************************************************************************************/
 
diff --git a/database.hpp b/database.hpp
index 2fced3f..02cad03 100644
--- a/database.hpp
+++ b/database.hpp
@@ -20,12 +20,13 @@ class Sequence;
 class Database {
 public:
 	Database(string);
-	virtual Sequence* findClosestSequence(Sequence*) = 0;
+	virtual ~Database();
+	virtual Sequence findClosestSequence(Sequence*) = 0;
 	virtual float getSearchScore();
 protected:
 	int numSeqs;
 	float searchScore;
-	vector<Sequence*> templateSequences;
+	vector<Sequence> templateSequences;
 };
 
 #endif
diff --git a/datavector.hpp b/datavector.hpp
index 692332f..b3c7c90 100644
--- a/datavector.hpp
+++ b/datavector.hpp
@@ -23,7 +23,7 @@ public:
 	DataVector(string l) : label(l) {};
 	DataVector(const DataVector& dv) : label(dv.label){};//, maxRank(dv.maxRank), numBins(dv.numBins), numSeqs(dv.numSeqs) {};
 	DataVector(ifstream&);
-	~DataVector(){};
+	virtual ~DataVector(){};
 	
 //	virtual int getNumBins()	{	return numBins;		}
 //	virtual int getNumSeqs()	{	return numSeqs;		}
diff --git a/deconvolutecommand.cpp b/deconvolutecommand.cpp
index 3ec5f73..2fe7a25 100644
--- a/deconvolutecommand.cpp
+++ b/deconvolutecommand.cpp
@@ -96,6 +96,7 @@ int DeconvoluteCommand::execute() {
 		fastamap->printNamesFile(out);
 		fastamap->printCondensedFasta(outFasta);
 		
+		in.close();
 		out.close();
 		outFasta.close();
 	
diff --git a/display.h b/display.h
index 0207bbf..ee827e5 100644
--- a/display.h
+++ b/display.h
@@ -18,6 +18,7 @@ public:
 	virtual void reset() = 0;
 	virtual void close() = 0;
 	virtual bool isCalcMultiple() = 0;
+	virtual ~Display() {}
 	
 private:
 
diff --git a/dist.h b/dist.h
index 4200bf9..6e42ae3 100644
--- a/dist.h
+++ b/dist.h
@@ -18,6 +18,7 @@ class Dist {
 	
 public:
 	Dist(){dist = 0;}
+	virtual ~Dist() {}
 	virtual void calcDist(Sequence, Sequence) = 0;
 	double getDist()	{	return dist;	}
 protected:
diff --git a/distancecommand.cpp b/distancecommand.cpp
index 065c14a..0c9d011 100644
--- a/distancecommand.cpp
+++ b/distancecommand.cpp
@@ -47,6 +47,7 @@ DistanceCommand::DistanceCommand(string option){
 				ifstream inFASTA;
 				openInputFile(fastafile, inFASTA);
 				alignDB = SequenceDB(inFASTA); 
+				inFASTA.close();
 			}
 
 			//check for optional parameter and set defaults
@@ -195,7 +196,7 @@ int DistanceCommand::execute(){
 			}
 		}
 #else
-		ifstream inFASTA
+		ifstream inFASTA;
 		driver(0, numSeqs, outputFile, cutoff);
 #endif
 		
diff --git a/distancedb.cpp b/distancedb.cpp
index 3cb739d..25c95c7 100644
--- a/distancedb.cpp
+++ b/distancedb.cpp
@@ -40,7 +40,7 @@ DistanceDB::DistanceDB(string fastaFileName, string distanceFileName) : Database
 
 /**************************************************************************************************/
 
-Sequence* DistanceDB::findClosestSequence(Sequence* candidateSeq){
+Sequence DistanceDB::findClosestSequence(Sequence* candidateSeq){
 	
 	hit simAccession = mostSimSequenceVector[searchIndex];
 //	string candidateSeqName, closestMatchSeqName, junk;
diff --git a/distancedb.hpp b/distancedb.hpp
index 9c13faf..8da1d10 100644
--- a/distancedb.hpp
+++ b/distancedb.hpp
@@ -17,7 +17,7 @@ class DistanceDB : public Database {
 	
 public:
 	DistanceDB(string, string);
-	Sequence* findClosestSequence(Sequence*);
+	Sequence findClosestSequence(Sequence*);
 	
 private:
 
diff --git a/engine.cpp b/engine.cpp
index 03422e2..a2d5250 100644
--- a/engine.cpp
+++ b/engine.cpp
@@ -47,8 +47,8 @@ bool InteractEngine::getInput(){
 		//bool errorFree;
 		//ErrorCheck* errorCheckor = new ErrorCheck();
 		
-		cout << "mothur v.1.3.0" << endl;
-		cout << "Last updated: 5/29/2009" << endl << endl;
+		cout << "mothur v.1.4.0" << endl;
+		cout << "Last updated: 6/21/2009" << endl << endl;
 		cout << "by" << endl;
 		cout << "Patrick D. Schloss" << endl << endl;
 		cout << "Department of Microbiology" << endl;
@@ -147,7 +147,7 @@ bool BatchEngine::getInput(){
 		int quitCommandCalled = 0;
 	
 		while(quitCommandCalled == 0){
-		
+	
 			if (inputBatchFile.eof()) { input = "quit()"; }
 			else { getline(inputBatchFile, input); }
 			
@@ -175,6 +175,8 @@ bool BatchEngine::getInput(){
 			}
 			gobble(inputBatchFile);
 		}
+		
+		inputBatchFile.close();
 		return 1;
 	}
 	catch(exception& e) {
@@ -280,12 +282,14 @@ string ScriptEngine::getNextCommand(string& commandString) {
 			commandString = commandString.substr(commandString.find_first_of(';')+1, commandString.length());
 		}else { commandString = ""; } //you have reached the last command.
 		
-		//get rid of any extra spaces in between commands
-		//string space = " ";
-		
-		//while(commandString.at(0) == ' ')
-			//commandString = commandString.substr(1, commandString.length());
-			
+		//get rid of spaces in between commands if any
+		if (commandString.length() > 0) {
+			while (commandString[0] == ' ') {  
+				commandString = commandString.substr(1,commandString.length());
+				if (commandString.length() == 0) {  break;  }
+			}
+		}
+					
 		return nextcommand;
 	}
 	catch(exception& e) {
diff --git a/fileoutput.h b/fileoutput.h
index 7dfb0c0..a047a20 100644
--- a/fileoutput.h
+++ b/fileoutput.h
@@ -9,7 +9,7 @@ class FileOutput {
 	
 public:
 	FileOutput(){};
-	~FileOutput(){};
+	virtual ~FileOutput(){};
 	
 	virtual void initFile(string) = 0;
 	virtual void initFile(string, vector<string>) = 0;
diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp
index 95d51f3..c38bfcb 100644
--- a/filterseqscommand.cpp
+++ b/filterseqscommand.cpp
@@ -104,6 +104,8 @@ void FilterSeqsCommand::doHard() {
 	openInputFile(hard, fileHandle);
 	
 	fileHandle >> filter;
+	
+	fileHandle.close();
 
 }
 
diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp
index ea6ef17..4fa8413 100644
--- a/getgroupcommand.cpp
+++ b/getgroupcommand.cpp
@@ -115,6 +115,7 @@ int GetgroupCommand::execute(){
 			if (in.eof() != true) { in >> nextLabel; }
 		}
 		
+		in.close();
 		out.close();
 		return 0;	
 	}
diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp
index e0c1720..40c656b 100644
--- a/getlabelcommand.cpp
+++ b/getlabelcommand.cpp
@@ -84,6 +84,8 @@ int GetlabelCommand::execute(){
 			in >> label;
 			count++;
 		}	
+		
+		in.close();
 		return 0;	
 	}
 
diff --git a/getlinecommand.cpp b/getlinecommand.cpp
index 6802978..800f9d8 100644
--- a/getlinecommand.cpp
+++ b/getlinecommand.cpp
@@ -84,6 +84,8 @@ int GetlineCommand::execute(){
 			in >> label;
 			count++;
 		}
+		
+		in.close();
 		return 0;		
 	}
 
diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp
index 35e6924..65c1806 100644
--- a/getoturepcommand.cpp
+++ b/getoturepcommand.cpp
@@ -156,11 +156,13 @@ void GetOTURepCommand::help(){
 //**********************************************************************************************************************
 
 GetOTURepCommand::~GetOTURepCommand(){
-	delete input;
-	delete read;
-	delete fasta;
-	if (groupfile != "") {
-		delete groupMap;
+	if (abort == false) {
+		delete input;  globaldata->ginput = NULL;
+		delete read;
+		delete fasta;
+		if (groupfile != "") {
+			delete groupMap;  globaldata->gGroupmap = NULL;
+		}
 	}
 }
 
@@ -177,8 +179,10 @@ int GetOTURepCommand::execute(){
 		//read fastafile
 		fasta->readFastaFile(in);
 		
+		in.close();
+		
 		//set format to list so input can get listvector
-//		globaldata->setFormat("list");
+		globaldata->setFormat("list");
 		
 		//if user gave a namesfile then use it
 		if (namesfile != "") {
diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp
index c978bb1..0dfaa63 100644
--- a/getrabundcommand.cpp
+++ b/getrabundcommand.cpp
@@ -108,6 +108,7 @@ void GetRAbundCommand::help(){
 //**********************************************************************************************************************
 
 GetRAbundCommand::~GetRAbundCommand(){
+	if (abort == false) {  globaldata->gListVector = NULL; }
 }
 
 //**********************************************************************************************************************
diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp
index 6670980..1e10736 100644
--- a/getsabundcommand.cpp
+++ b/getsabundcommand.cpp
@@ -186,7 +186,7 @@ int GetSAbundCommand::execute(){
 			sabund->print(out);
 			delete sabund;
 		}
-		delete lastOrder;
+		delete lastOrder;  globaldata->gorder = NULL;
 
 		out.close();
 		return 0;		
diff --git a/globaldata.cpp b/globaldata.cpp
index fe3c11b..0d728a1 100644
--- a/globaldata.cpp
+++ b/globaldata.cpp
@@ -1,6 +1,9 @@
 
 
 #include "globaldata.hpp"
+#include "sharedlistvector.h"
+#include "inputdata.h"
+#include "fullmatrix.h"
 
 /*******************************************************/
 
@@ -50,6 +53,16 @@ GlobalData::GlobalData() {
 	clear();
 	gListVector = NULL;		
 	gSparseMatrix = NULL;	
+	ginput = NULL;
+	gorder = NULL;
+	glist = NULL;
+	gSharedList = NULL;
+	sabund = NULL;
+	rabund = NULL;
+	gGroupmap = NULL;
+	gMatrix = NULL;
+	gTreemap = NULL;
+	gSequenceDB = NULL;
 }
 /*******************************************************/
 
@@ -74,11 +87,24 @@ void GlobalData::clear() {
 
 /******************************************************/
 void GlobalData::newRead() {
-	try{
+	try{	
+			//remove old file names
 			clear();
-			gGroupmap = NULL;
-			gListVector = NULL;
-			gSparseMatrix = NULL;
+			
+			//free memory
+			if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
+			if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
+			if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
+			if (ginput != NULL) { delete ginput; ginput = NULL;}
+			if (gorder != NULL) { delete gorder; gorder = NULL; }
+			if (glist != NULL) { delete glist; glist = NULL;}
+			if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
+			if (sabund != NULL) { delete sabund; sabund = NULL;}
+			if (rabund != NULL) { delete rabund; rabund = NULL; }
+			if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
+			if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
+			if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
+
 			gTree.clear();
 			Treenames.clear();
 			labels.clear(); lines.clear(); Groups.clear();
@@ -100,9 +126,28 @@ void GlobalData::newRead() {
 /******************************************************/
 GlobalData::~GlobalData() {
 	_uniqueInstance = 0;
-	if(gListVector != NULL)		{	delete gListVector;		}
-	if(gSparseMatrix != NULL)	{	delete gSparseMatrix;	}
-	if(gorder != NULL)			{	delete gorder;		}
+	try {
+		if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
+		if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
+		if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
+		if (ginput != NULL) { delete ginput; ginput = NULL;}
+		if (gorder != NULL) { delete gorder; gorder = NULL; }
+		if (glist != NULL) { delete glist; glist = NULL;}
+		if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
+		if (sabund != NULL) { delete sabund; sabund = NULL;}
+		if (rabund != NULL) { delete rabund; rabund = NULL; }
+		if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
+		if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
+		if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
+	}
+	catch(exception& e) {
+		cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function ~GlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+		exit(1);
+	}
+	catch(...) {
+		cout << "An unknown error has occurred in the GlobalData class function ~GlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+		exit(1);
+	}
 }
 /*******************************************************/
 
diff --git a/globaldata.hpp b/globaldata.hpp
index 6515521..6f66cbe 100644
--- a/globaldata.hpp
+++ b/globaldata.hpp
@@ -9,6 +9,8 @@
 #include "listvector.hpp"
 #include "tree.h"
 #include "sparsematrix.hpp"
+#include "sequencedb.h"
+
 
 class ListVector;
 class SharedListVector;
diff --git a/gotohoverlap.hpp b/gotohoverlap.hpp
index bf3c636..85176ef 100644
--- a/gotohoverlap.hpp
+++ b/gotohoverlap.hpp
@@ -30,6 +30,7 @@ class GotohOverlap : public Alignment {
 public:
 	GotohOverlap(float, float, float, float, int);
 	void align(string, string);
+	~GotohOverlap() {}
 	
 private:
 	float gapOpen;
diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp
index d4e893b..7a729c6 100644
--- a/heatmapcommand.cpp
+++ b/heatmapcommand.cpp
@@ -128,9 +128,10 @@ void HeatMapCommand::help(){
 //**********************************************************************************************************************
 
 HeatMapCommand::~HeatMapCommand(){
-	
-	delete read;
-	delete heatmap;
+	if (abort == false) {
+		delete read;
+		delete heatmap;
+	}
 }
 
 //**********************************************************************************************************************
@@ -272,11 +273,11 @@ int HeatMapCommand::execute(){
 				heatmap->getPic(lastRAbund);
 			}
 		
-			delete lastRAbund;
+			delete lastRAbund; globaldata->rabund = NULL;
 
 		}
 		
-		delete input;
+		delete input; globaldata->ginput = NULL;
 		return 0;
 	}
 	catch(exception& e) {
diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp
index 3b0d798..f332994 100644
--- a/heatmapsimcommand.cpp
+++ b/heatmapsimcommand.cpp
@@ -171,10 +171,12 @@ void HeatMapSimCommand::help(){
 //**********************************************************************************************************************
 
 HeatMapSimCommand::~HeatMapSimCommand(){
-	delete input;
-	delete read;
-	delete heatmap;
-	delete validCalculator;
+	if (abort == false) {
+		delete input;  globaldata->ginput = NULL;
+		delete read;
+		delete heatmap;
+		delete validCalculator;
+	}
 }
 
 //**********************************************************************************************************************
diff --git a/inputdata.cpp b/inputdata.cpp
index b237bb4..b4373c9 100644
--- a/inputdata.cpp
+++ b/inputdata.cpp
@@ -72,7 +72,7 @@ ListVector* InputData::getListVector(){
 			return list;
 		}
 		else{
-			return 0;
+			return NULL;
 		}
 	}
 	catch(exception& e) {
@@ -98,7 +98,7 @@ SharedListVector* InputData::getSharedListVector(){
 			return SharedList;
 		}
 		else{
-			return 0;
+			return NULL;
 		}
 	}
 	catch(exception& e) {
@@ -124,7 +124,7 @@ SharedOrderVector* InputData::getSharedOrderVector(){
 			return SharedOrder;
 			
 		}else{
-			return 0;
+			return NULL;
 		}
 	}
 	catch(exception& e) {
@@ -170,7 +170,7 @@ OrderVector* InputData::getOrderVector(){
 			return output;
 		}
 		else{
-			return 0;
+			return NULL;
 		}
 	}
 	catch(exception& e) {
@@ -246,7 +246,7 @@ SAbundVector* InputData::getSAbundVector(){
 			return sabund;
 		}
 		else{
-			return 0;
+			return NULL;
 		}
 	}
 	catch(exception& e) {
diff --git a/kmerdb.cpp b/kmerdb.cpp
index 572acda..40cc1f6 100644
--- a/kmerdb.cpp
+++ b/kmerdb.cpp
@@ -50,10 +50,17 @@ KmerDB::KmerDB(string fastaFileName, int kSize) : Database(fastaFileName), kmerS
 	cout << "DONE." << endl << endl;	cout.flush();
 
 }
+/**************************************************************************************************/
+
+KmerDB::~KmerDB(){														
+	
+		//for (int i = 0; i < templateSequences.size(); i++) {  delete templateSequences[i]; }
+		// templateSequences.clear(); 
+}
 
 /**************************************************************************************************/
 
-Sequence* KmerDB::findClosestSequence(Sequence* candidateSeq){
+Sequence KmerDB::findClosestSequence(Sequence* candidateSeq){
 	
 	Kmer kmer(kmerSize);
 	
@@ -94,7 +101,7 @@ void KmerDB::generateKmerDB(string kmerDBName){
 	
 	for(int i=0;i<numSeqs;i++){								//	for all of the template sequences...
 
-		string seq = templateSequences[i]->getUnaligned();	//	...take the unaligned sequence...
+		string seq = templateSequences[i].getUnaligned();	//	...take the unaligned sequence...
 		int numKmers = seq.length() - kmerSize + 1;
 		
 		vector<int> seenBefore(maxKmer+1,0);
diff --git a/kmerdb.hpp b/kmerdb.hpp
index eb10061..5019858 100644
--- a/kmerdb.hpp
+++ b/kmerdb.hpp
@@ -25,7 +25,8 @@ class KmerDB : public Database {
 	
 public:
 	KmerDB(string, int);
-	Sequence* findClosestSequence(Sequence*);
+	~KmerDB();
+	Sequence findClosestSequence(Sequence*);
 
 private:
 	void generateKmerDB(string);
diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp
index 75e6137..fd41391 100644
--- a/libshuffcommand.cpp
+++ b/libshuffcommand.cpp
@@ -256,7 +256,7 @@ void LibShuffCommand::printCoverageFile() {
 			}
 			outCov << endl;
 		}
-		
+		outCov.close();
 	}
 	catch(exception& e) {
 		cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function printCoverageFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -305,7 +305,7 @@ void LibShuffCommand::printSummaryFile() {
 			}
 		}
 		
-		
+		outSum.close();
 	}
 	catch(exception& e) {
 		cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function printSummaryFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
diff --git a/matrixoutputcommand.cpp b/matrixoutputcommand.cpp
index e848647..4ae8e24 100644
--- a/matrixoutputcommand.cpp
+++ b/matrixoutputcommand.cpp
@@ -170,9 +170,11 @@ void MatrixOutputCommand::help(){
 //**********************************************************************************************************************
 
 MatrixOutputCommand::~MatrixOutputCommand(){
-	delete input;
-	delete read;
-	delete validCalculator;
+	if (abort == false) {
+		delete input; globaldata->ginput = NULL;
+		delete read;
+		delete validCalculator;
+	}
 }
 
 //**********************************************************************************************************************
diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp
index 3342c48..497d535 100644
--- a/mergefilecommand.cpp
+++ b/mergefilecommand.cpp
@@ -88,6 +88,8 @@ int MergeFileCommand::execute(){
 			
 			inputFile.close();
 		}
+		
+		outputFile.close();
 		return 0;
 	}
 	catch(exception& e) {
diff --git a/observable.h b/observable.h
index 457a176..05e537a 100644
--- a/observable.h
+++ b/observable.h
@@ -13,6 +13,7 @@ public:
 	virtual void registerDisplay(Display*) = 0;
 	virtual void removeDisplay(Display*) = 0;
 	virtual void notifyDisplays() = 0;	
+	virtual ~Observable() {}
 };
 
 /***********************************************************************/
diff --git a/parselistcommand.cpp b/parselistcommand.cpp
index 332074d..c12bd47 100644
--- a/parselistcommand.cpp
+++ b/parselistcommand.cpp
@@ -184,9 +184,11 @@ int ParseListCommand::execute(){
 //**********************************************************************************************************************
 
 ParseListCommand::~ParseListCommand(){
-	delete list;
-	delete input;
-	delete read;	
+	
+		globaldata->gSharedList = NULL;
+		delete input;  globaldata->ginput = NULL;
+		delete read;
+	
 }
 //**********************************************************************************************************************
 void ParseListCommand::process(SharedListVector* thisList) {
diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp
index 6bf42fc..8820328 100644
--- a/rarefactcommand.cpp
+++ b/rarefactcommand.cpp
@@ -171,11 +171,12 @@ void RareFactCommand::help(){
 //**********************************************************************************************************************
 
 RareFactCommand::~RareFactCommand(){
-	delete order;
-	delete input;
-	delete rCurve;
-	delete read;
-	delete validCalculator;
+	if (abort == false) {
+		globaldata->gorder = NULL;
+		delete input;  globaldata->ginput = NULL;
+		delete read;
+		delete validCalculator;
+	}
 }
 
 //**********************************************************************************************************************
diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp
index fdc9678..6461b3b 100644
--- a/rarefactsharedcommand.cpp
+++ b/rarefactsharedcommand.cpp
@@ -154,10 +154,11 @@ void RareFactSharedCommand::help(){
 //**********************************************************************************************************************
 
 RareFactSharedCommand::~RareFactSharedCommand(){
-	delete input;
-	delete rCurve;
-	delete read;
-	delete validCalculator;
+	if (abort == false) {
+		delete input;   globaldata->ginput = NULL;
+		delete read;
+		delete validCalculator;
+	}
 }
 
 //**********************************************************************************************************************
diff --git a/readcolumn.cpp b/readcolumn.cpp
index 1d29208..59c3bd5 100644
--- a/readcolumn.cpp
+++ b/readcolumn.cpp
@@ -153,8 +153,8 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){
 /***********************************************************************/
 
 ReadColumnMatrix::~ReadColumnMatrix(){
-	delete D;
-	delete list;
+	//delete D;
+	//delete list;
 }
 
 
diff --git a/readdistcommand.cpp b/readdistcommand.cpp
index b03f12e..392d12b 100644
--- a/readdistcommand.cpp
+++ b/readdistcommand.cpp
@@ -53,8 +53,8 @@ ReadDistCommand::ReadDistCommand(string option){
 			else if (groupfile == "not found") { groupfile = ""; }
 			else {  
 				globaldata->setGroupFile(groupfile); 
-				groupMap = new GroupMap(groupfile);
-				groupMap->readMap();
+				//groupMap = new GroupMap(groupfile);
+				//groupMap->readMap();
 			}
 
 			namefile = validParameter.validFile(parameters, "name", true);
@@ -150,8 +150,9 @@ void ReadDistCommand::help(){
 //**********************************************************************************************************************
 
 ReadDistCommand::~ReadDistCommand(){
-	delete read;
-	delete nameMap;
+	if (abort == false) {
+		if (format != "matrix") { delete read; delete nameMap; }
+	}
 }
 
 //**********************************************************************************************************************
@@ -164,16 +165,20 @@ int ReadDistCommand::execute(){
 			ifstream in;
 			openInputFile(distFileName, in);
 			matrix = new FullMatrix(in); //reads the matrix file
+			in.close();
 			//memory leak prevention
-			//if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix;  }
+			if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix;  }
 			globaldata->gMatrix = matrix; //save matrix for coverage commands
 		}else {
 			read->read(nameMap);
 			//to prevent memory leak
-			if (globaldata->gListVector != NULL) { delete globaldata->gListVector;  }
+
+			if (globaldata->gListVector != NULL) {  delete globaldata->gListVector;  }
 			globaldata->gListVector = read->getListVector();
+
 			if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix;  }
 			globaldata->gSparseMatrix = read->getMatrix();
+
 		}
 		return 0;
 	}
diff --git a/readmatrix.hpp b/readmatrix.hpp
index 66480e7..d8f9bd1 100644
--- a/readmatrix.hpp
+++ b/readmatrix.hpp
@@ -22,6 +22,7 @@ class ReadMatrix {
 
 public:
 	ReadMatrix(){	D = new SparseMatrix();	}
+	virtual ~ReadMatrix() {}
 	virtual void read(NameAssignment*){};
 	virtual void read(GlobalData* globaldata){};
 	void setCutoff(float c)			{	cutoff = c;		}
diff --git a/readotu.cpp b/readotu.cpp
index 286a2be..b97c902 100644
--- a/readotu.cpp
+++ b/readotu.cpp
@@ -13,7 +13,7 @@
 
 ReadOTUFile::ReadOTUFile(string pf): philFile(pf){
 	
-	openInputFile(philFile, fileHandle);
+	//openInputFile(philFile, fileHandle);
 }
 
 /***********************************************************************/
diff --git a/readotu.h b/readotu.h
index e318af4..b259733 100644
--- a/readotu.h
+++ b/readotu.h
@@ -27,7 +27,7 @@ public:
 	~ReadOTUFile();
 	void read(GlobalData* globaldata);
 private:
-	ifstream fileHandle;
+	//ifstream fileHandle;
 	string philFile;
 	InputData* input;
 	InputData* inputSabund;
diff --git a/readphylip.cpp b/readphylip.cpp
index bc39b52..a1063e9 100644
--- a/readphylip.cpp
+++ b/readphylip.cpp
@@ -180,6 +180,6 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){
 /***********************************************************************/
 
 ReadPhylipMatrix::~ReadPhylipMatrix(){
-        delete D;
-        delete list;
+       // delete D;
+       // delete list;
 }
diff --git a/readtree.cpp b/readtree.cpp
index d3790df..670c6e0 100644
--- a/readtree.cpp
+++ b/readtree.cpp
@@ -177,6 +177,8 @@ int ReadNewickTree::read() {
 		}
 		
 		if (error != 0) { readOk = error; } 
+		
+		filehandle.close();
 		return readOk;
 	}
 	catch(exception& e) {
diff --git a/readtree.h b/readtree.h
index c8e866a..0cdf8b1 100644
--- a/readtree.h
+++ b/readtree.h
@@ -23,7 +23,7 @@ class Tree;
 class ReadTree {
 	public:
 		ReadTree(); 
-		~ReadTree() {};
+		virtual ~ReadTree() {};
 		
 		virtual int read() = 0;
 		int readSpecialChar(istream&, char, string);
diff --git a/readtreecommand.cpp b/readtreecommand.cpp
index 88e34ff..d301b13 100644
--- a/readtreecommand.cpp
+++ b/readtreecommand.cpp
@@ -33,14 +33,13 @@ ReadTreeCommand::ReadTreeCommand(string option){
 				if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
 			}
 			
-			globaldata->runParse = true;
 			globaldata->newRead();
 			
 			//check for required parameters
 			treefile = validParameter.validFile(parameters, "tree", true);
 			if (treefile == "not open") { abort = true; }
 			else if (treefile == "not found") { treefile = ""; cout << "tree is a required parameter for the read.tree command." << endl; abort = true;  }	
-//			else {  globaldata->setTreeFile(treefile);  globaldata->setFormat("tree"); 	}
+			else {  globaldata->setTreeFile(treefile);  globaldata->setFormat("tree"); 	}
 			
 			groupfile = validParameter.validFile(parameters, "group", true);
 			if (groupfile == "not open") { abort = true; }	
diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp
index 1c70a2b..ca1d616 100644
--- a/screenseqscommand.cpp
+++ b/screenseqscommand.cpp
@@ -160,6 +160,9 @@ int ScreenSeqsCommand::execute(){
 		if(groupfile != "")		{	screenGroupFile(badSeqNames);		}
 		if(alignreport != "")	{	screenAlignReport(badSeqNames);		}
 		
+		goodSeqOut.close();
+		badSeqOut.close();
+		inFASTA.close();
 		return 0;
 	}
 	catch(exception& e) {
diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp
index 24ef1d1..3259931 100644
--- a/seqsummarycommand.cpp
+++ b/seqsummarycommand.cpp
@@ -139,6 +139,7 @@ int SeqSummaryCommand::execute(){
 		cout << "Maximum:\t" << startPosition[ptile100] << '\t' << endPosition[ptile100] << '\t' << seqLength[ptile100] << '\t' << ambigBases[ptile100] << '\t' << longHomoPolymer[ptile100] << endl;
 		cout << "# of Seqs:\t" << numSeqs << endl;
 		
+		outSummary.close();
 		return 0;
 	}
 	catch(exception& e) {
diff --git a/shen.cpp b/shen.cpp
index 152a138..3d1c277 100644
--- a/shen.cpp
+++ b/shen.cpp
@@ -27,7 +27,9 @@ EstOutput Shen::getValues(SAbundVector* rank){
 		double f0 = ace[0]-rank->getNumBins();
 		
 		data[0] = f0 * (1 - pow(1 - f1/n/f0, m));
-
+		
+		delete calc;
+		
 		return data;
 	}
 	catch(exception& e) {
diff --git a/suffixdb.cpp b/suffixdb.cpp
index 15f7753..5e6fd10 100644
--- a/suffixdb.cpp
+++ b/suffixdb.cpp
@@ -35,7 +35,7 @@ SuffixDB::SuffixDB(string fastaFileName) : Database(fastaFileName) {
 
 /**************************************************************************************************/
 
-Sequence* SuffixDB::findClosestSequence(Sequence* candidateSeq){
+Sequence SuffixDB::findClosestSequence(Sequence* candidateSeq){
 
 	int minValue = 2000;
 	int closestSequenceNo = 0;
@@ -52,3 +52,11 @@ Sequence* SuffixDB::findClosestSequence(Sequence* candidateSeq){
 }
 
 /**************************************************************************************************/
+
+SuffixDB::~SuffixDB(){														
+	
+	for (int i = (suffixForest.size()-1); i >= 0; i--) {  suffixForest.pop_back();  }
+	// templateSequences.clear();
+
+}
+/**************************************************************************************************/
diff --git a/suffixdb.hpp b/suffixdb.hpp
index 15114cf..f211aa7 100644
--- a/suffixdb.hpp
+++ b/suffixdb.hpp
@@ -27,7 +27,8 @@ class SuffixDB : public Database {
 	
 public:
 	SuffixDB(string);
-	Sequence* findClosestSequence(Sequence*);
+	~SuffixDB();
+	Sequence findClosestSequence(Sequence*);
 
 private:
 	vector<SuffixTree> suffixForest;
diff --git a/suffixnodes.hpp b/suffixnodes.hpp
index 82d4be9..63918fa 100644
--- a/suffixnodes.hpp
+++ b/suffixnodes.hpp
@@ -24,6 +24,7 @@ class SuffixNode {
 	
 public:
 	SuffixNode(int, int, int);
+	virtual ~SuffixNode() {}
 	virtual void print(string, int)	= 0;
 	virtual void setChildren(char, int);
 	virtual int getNumChildren();
@@ -49,6 +50,7 @@ class SuffixLeaf : public SuffixNode {	//	most of the methods are already set in
 	
 public:
 	SuffixLeaf(int, int, int);		//	we just need to define a constructor and
+	~SuffixLeaf() {}
 	void print(string, int);		//	print method
 };
 
@@ -58,6 +60,7 @@ class SuffixBranch : public SuffixNode {
 	
 public:
 	SuffixBranch(int, int, int);
+	~SuffixBranch() {}
 	void print(string, int);		//	need a special method for printing the node because there are children
 	void eraseChild(char);			//	need a special method for erasing the children
 	void setChildren(char, int);	//	need a special method for setting children
diff --git a/suffixtree.cpp b/suffixtree.cpp
index 492460d..0dbe2c0 100644
--- a/suffixtree.cpp
+++ b/suffixtree.cpp
@@ -41,16 +41,17 @@ SuffixTree::SuffixTree(){}
 
 SuffixTree::~SuffixTree(){
 	for(int i=0;i<nodeVector.size();i++){	delete nodeVector[i];	}	
+	nodeVector.clear();
 }
 
 //********************************************************************************************************************
 
-void SuffixTree::loadSequence(Sequence* seq){
+void SuffixTree::loadSequence(Sequence seq){
 	nodeCounter = 0;							//	initially there are 0 nodes in the tree
 	activeStartPosition = 0;
 	activeEndPosition = -1;						
-	seqName = seq->getName();
-	sequence = seq->convert2ints();
+	seqName = seq.getName();
+	sequence = seq.convert2ints();
 	sequence += '5';							//	this essentially concatenates a '$' to the end of the sequence to
 	int seqLength = sequence.length();			//	make it a cononical suffix tree
 	
diff --git a/suffixtree.hpp b/suffixtree.hpp
index 28b6fd1..b85cee9 100644
--- a/suffixtree.hpp
+++ b/suffixtree.hpp
@@ -38,7 +38,7 @@ public:
 	~SuffixTree();
 //	SuffixTree(string, string);
 
-	void loadSequence(Sequence*);
+	void loadSequence(Sequence);
 	string getSeqName();
 	void print();	
 	int countSuffixes(string, int&);
diff --git a/summarycommand.cpp b/summarycommand.cpp
index fa6d11a..ee4ba9f 100644
--- a/summarycommand.cpp
+++ b/summarycommand.cpp
@@ -194,10 +194,12 @@ void SummaryCommand::help(){
 //**********************************************************************************************************************
 
 SummaryCommand::~SummaryCommand(){
-	delete sabund;
-	delete input;
-	delete read;
-	delete validCalculator;
+	if (abort == false) {
+		delete input;  globaldata->ginput = NULL;
+		delete read;
+		delete validCalculator;
+		globaldata->sabund = NULL;
+	}
 }
 
 //**********************************************************************************************************************
@@ -272,7 +274,7 @@ int SummaryCommand::execute(){
 				outputFileHandle << endl;
 			}		
 
-			if (count != 1) { delete lastSAbund; }
+			if (count != 1) { delete lastSAbund;  }
 			lastSAbund = sabund;			
 
 			sabund = input->getSAbundVector();
@@ -304,6 +306,8 @@ int SummaryCommand::execute(){
 			outputFileHandle << endl;
 		}
 		
+		outputFileHandle.close();
+		
 		delete lastSAbund;
 		return 0;
 	}
diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp
index 7c1275f..4006b2d 100644
--- a/summarysharedcommand.cpp
+++ b/summarysharedcommand.cpp
@@ -204,8 +204,10 @@ void SummarySharedCommand::help(){
 //**********************************************************************************************************************
 
 SummarySharedCommand::~SummarySharedCommand(){
-	delete read;
-	delete validCalculator;
+	if (abort == false) {
+		delete read;
+		delete validCalculator;
+	}
 }
 
 //**********************************************************************************************************************
@@ -335,7 +337,7 @@ int SummarySharedCommand::execute(){
 		
 		for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
 		
-		delete input;
+		delete input;  globaldata->ginput = NULL;
 
 		return 0;
 	}
diff --git a/tree.cpp b/tree.cpp
index c078f4f..ee17e6f 100644
--- a/tree.cpp
+++ b/tree.cpp
@@ -668,7 +668,7 @@ void Tree::parseTreeFile() {
 				if(number == ";") { globaldata->Treenames.pop_back(); }  //in case ';' from translation is on next line instead of next to last name
 			}
 		}
-		
+		filehandle.close();
 	}
 	catch(exception& e) {
 		cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
diff --git a/treecalculator.h b/treecalculator.h
index 16663bf..35d061c 100644
--- a/treecalculator.h
+++ b/treecalculator.h
@@ -24,7 +24,7 @@ class TreeCalculator {
 public:
 	TreeCalculator(){};
 	TreeCalculator(string n) : name(n) {};
-	~TreeCalculator(){};
+	virtual ~TreeCalculator(){};
 	virtual EstOutput getValues(Tree*) = 0;	
 	virtual EstOutput getValues(Tree*, string, string) = 0;
 	
diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp
index 0f106c4..88b1b46 100644
--- a/treegroupscommand.cpp
+++ b/treegroupscommand.cpp
@@ -205,11 +205,13 @@ void TreeGroupCommand::help(){
 //**********************************************************************************************************************
 
 TreeGroupCommand::~TreeGroupCommand(){
-	delete input;
-	if (format == "sharedfile") {delete read;}
-	else { delete readMatrix;  delete matrix; delete list; }
-	delete tmap;
-	delete validCalculator;
+	if (abort == false) {
+		
+		if (format == "sharedfile") { delete read;  delete input; globaldata->ginput = NULL;}
+		else { delete readMatrix;  delete matrix; delete list; }
+		delete tmap;
+		delete validCalculator;
+	}
 	
 }
 
diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp
index e616b74..1989365 100644
--- a/trimseqscommand.cpp
+++ b/trimseqscommand.cpp
@@ -179,6 +179,7 @@ int TrimSeqsCommand::execute(){
 				if(qThreshold != 0)		{	success = stripQualThreshold(currSeq, qFile);	}
 				else if(qAverage != 0)	{	success = cullQualAverage(currSeq, qFile);		}
 				if(!success)			{	trashCode += 'q';								}
+				qFile.close();
 			}
 			if(barcodes.size() != 0){
 				success = stripBarcode(currSeq, group);
@@ -308,6 +309,8 @@ void TrimSeqsCommand::getOligos(vector<ofstream*>& outFASTAVec){
 		}
 	}
 	
+	inOligos.close();
+	
 	numFPrimers = forPrimer.size();
 	numRPrimers = revPrimer.size();
 }
diff --git a/venncommand.cpp b/venncommand.cpp
index 70c136b..343461a 100644
--- a/venncommand.cpp
+++ b/venncommand.cpp
@@ -181,10 +181,13 @@ void VennCommand::help(){
 //**********************************************************************************************************************
 
 VennCommand::~VennCommand(){
-	delete input;
-	delete read;
-	delete venn;
-	for (int i = 0; i < vennCalculators.size(); i++) {	delete vennCalculators[i];	}
+	if (abort == false) {
+		delete input; globaldata->ginput = NULL;
+		delete read;
+		delete venn;
+		globaldata->sabund = NULL;
+	}
+	
 }
 
 //**********************************************************************************************************************
@@ -342,6 +345,7 @@ int VennCommand::execute(){
 			delete lastSAbund;
 		}
 		
+		for (int i = 0; i < vennCalculators.size(); i++) {	delete vennCalculators[i];	}
 		return 0;
 	}
 	catch(exception& e) {