Index: src/Fragmentation/Fragmentation.cpp
===================================================================
--- src/Fragmentation/Fragmentation.cpp	(revision 42127c3196b85e2b52749471ca9014640269b9fb)
+++ src/Fragmentation/Fragmentation.cpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
@@ -83,5 +83,4 @@
   bool CheckOrder = false;
   Graph **FragmentList = NULL;
-  Graph *ParsedFragmentList = NULL;
   Graph TotalGraph;     // graph with all keysets however local numbers
   int TotalNumberOfKeySets = 0;
@@ -126,5 +125,6 @@
 
   // ===== 3. if structure still valid, parse key set file and others =====
-  FragmentationToDo = FragmentationToDo && ParseKeySetFile(prefix, ParsedFragmentList);
+  Graph ParsedFragmentList;
+  FragmentationToDo = FragmentationToDo && ParsedFragmentList.ParseKeySetFile(prefix);
 
   // ===== 4. check globally whether there's something to do actually (first adaptivity check)
@@ -138,5 +138,5 @@
     ListOfLocalAtoms[i] = NULL;
   FragmentCounter = 0;
-  Subgraphs->next->AssignKeySetsToFragment(mol, ParsedFragmentList, ListOfLocalAtoms, FragmentList, FragmentCounter, true);
+  Subgraphs->next->AssignKeySetsToFragment(mol, &ParsedFragmentList, ListOfLocalAtoms, FragmentList, FragmentCounter, true);
   delete[](ListOfLocalAtoms);
 
@@ -146,5 +146,5 @@
   AtomMask[mol->getAtomCount()] = false;
   FragmentationToDo = false;  // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards
-  while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, prefix))) {
+  while ((CheckOrder = CheckOrderAtSite(AtomMask, &ParsedFragmentList, Order, prefix))) {
     FragmentationToDo = FragmentationToDo || CheckOrder;
     AtomMask[mol->getAtomCount()] = true;   // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
@@ -171,5 +171,4 @@
   delete[](RootStack);
   delete[](AtomMask);
-  delete(ParsedFragmentList);
 
   // ==================================== End of FRAGMENTATION ============================================
@@ -224,5 +223,5 @@
 
     // store keysets file
-    StoreKeySetFile(TotalGraph, prefix);
+    TotalGraph.StoreKeySetFile(prefix);
 
     {
@@ -465,5 +464,5 @@
       return false;
     }
-    map<int,KeySet> *IndexKeySetList = GraphToIndexedKeySet(GlobalKeySetList);
+    map<int,KeySet> *IndexKeySetList = GlobalKeySetList->GraphToIndexedKeySet();
 
     // parse the EnergyPerFragment file
Index: src/Fragmentation/Graph.cpp
===================================================================
--- src/Fragmentation/Graph.cpp	(revision 42127c3196b85e2b52749471ca9014640269b9fb)
+++ src/Fragmentation/Graph.cpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
@@ -20,7 +20,15 @@
 #include "CodePatterns/MemDebug.hpp"
 
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <string>
+
 #include "Graph.hpp"
 
 #include "CodePatterns/Log.hpp"
+
+#include "Helpers/defs.hpp"
+#include "Helpers/helpers.hpp"
 
 /** Constructor for class Graph.
@@ -56,2 +64,169 @@
 };
 
+/** Parses the KeySet file and fills \a this from the known molecule structure.
+ * Does two-pass scanning:
+ * -# Scans the keyset file and initialises a temporary graph
+ * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
+ * Finally, the temporary graph is inserted into the given \a FragmentList for return.
+ * \param &path path to file
+ * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
+ */
+bool Graph::ParseKeySetFile(std::string &path)
+{
+  bool status = true;
+  std::ifstream InputFile;
+  std::stringstream line;
+  GraphTestPair testGraphInsert;
+  int NumberOfFragments = 0;
+  std::string filename;
+
+  // 1st pass: open file and read
+  LOG(1, "INFO: Parsing the KeySet file ... ");
+  filename = path + KEYSETFILE;
+  InputFile.open(filename.c_str());
+  if (InputFile.good()) {
+    // each line represents a new fragment
+    char buffer[MAXSTRINGSIZE];
+    // 1. parse keysets and insert into temp. graph
+    while (!InputFile.eof()) {
+      InputFile.getline(buffer, MAXSTRINGSIZE);
+      KeySet CurrentSet;
+      if ((strlen(buffer) > 0) && (CurrentSet.ScanBufferIntoKeySet(buffer))) {  // if at least one valid atom was added, write config
+        testGraphInsert = insert(GraphPair (CurrentSet,pair<int,double>(NumberOfFragments++,1)));  // store fragment number and current factor
+        if (!testGraphInsert.second) {
+          ELOG(0, "KeySet file must be corrupt as there are two equal key sets therein!");
+          performCriticalExit();
+        }
+      }
+    }
+    // 2. Free and done
+    InputFile.close();
+    InputFile.clear();
+    LOG(1, "INFO: ... done.");
+  } else {
+    ELOG(1, "File " << filename << " not found.");
+    status = false;
+  }
+
+  return status;
+};
+
+/** Stores key sets to file.
+ * \param &path path to file
+ * \return true - file written successfully, false - writing failed
+ */
+bool Graph::StoreKeySetFile(std::string &path)
+{
+  bool status =  true;
+  std::string line = path + KEYSETFILE;
+  std::ofstream output(line.c_str());
+
+  // open KeySet file
+  LOG(1, "INFO: Saving key sets of the total graph ... ");
+  if(output.good()) {
+    for(Graph::iterator runner = begin(); runner != end(); runner++) {
+      for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
+        if (sprinter != (*runner).first.begin())
+          output << "\t";
+        output << *sprinter;
+      }
+      output << std::endl;
+    }
+    LOG(1, "INFO: done.");
+  } else {
+    ELOG(0, "Unable to open " << line << " for writing keysets!");
+    performCriticalExit();
+    status = false;
+  }
+  output.close();
+  output.clear();
+
+  return status;
+};
+
+/** Parses the TE factors file and fills \a *FragmentList from the known molecule structure.
+ * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
+ * \param *path path to file
+ * \return true - parsing successfully, false - failure on parsing
+ */
+bool Graph::ParseTEFactorsFile(char *path)
+{
+  bool status = true;
+  std::ifstream InputFile;
+  std::stringstream line;
+  GraphTestPair testGraphInsert;
+  int NumberOfFragments = 0;
+  double TEFactor;
+  char filename[MAXSTRINGSIZE];
+
+  // 2nd pass: open TEFactors file and read
+  LOG(1, "INFO: Parsing the TEFactors file ... ");
+  sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, TEFACTORSFILE);
+  InputFile.open(filename);
+  if (InputFile != NULL) {
+    // 3. add found TEFactors to each keyset
+    NumberOfFragments = 0;
+    for(Graph::iterator runner = begin();runner != end(); runner++) {
+      if (!InputFile.eof()) {
+        InputFile >> TEFactor;
+        (*runner).second.second = TEFactor;
+        LOG(2, "INFO: Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << ".");
+      } else {
+        status = false;
+        break;
+      }
+    }
+    // 4. Free and done
+    InputFile.close();
+    LOG(1, "INFO: done.");
+  } else {
+    LOG(1, "INFO: File " << filename << " not found.");
+    status = false;
+  }
+
+  return status;
+};
+
+/** Stores TEFactors to file.
+ * \param *out output stream for debugging
+ * \param KeySetList Graph with factors
+ * \param *path path to file
+ * \return true - file written successfully, false - writing failed
+ */
+bool Graph::StoreTEFactorsFile(char *path)
+{
+  ofstream output;
+  bool status =  true;
+  string line;
+
+  // open TEFactors file
+  line = path;
+  line.append("/");
+  line += FRAGMENTPREFIX;
+  line += TEFACTORSFILE;
+  output.open(line.c_str(), ios::out);
+  LOG(1, "INFO: Saving TEFactors of the total graph ... ");
+  if(output != NULL) {
+    for(Graph::iterator runner = begin(); runner != end(); runner++)
+      output << (*runner).second.second << endl;
+    LOG(1, "INFO: done." << endl);
+  } else {
+    ELOG(2, "INFO: failed to open " << line << "." << endl);
+    status = false;
+  }
+  output.close();
+
+  return status;
+};
+
+/** For a given graph, sorts KeySets into a (index, keyset) map.
+ * \return ref to allocated map from index to keyset
+ */
+std::map<int,KeySet> * Graph::GraphToIndexedKeySet() const
+{
+  map<int,KeySet> *IndexKeySetList = new map<int,KeySet>;
+  for(const_iterator runner = begin(); runner != end(); runner++) {
+    IndexKeySetList->insert( pair<int,KeySet>(runner->second.first,runner->first) );
+  }
+  return IndexKeySetList;
+};
Index: src/Fragmentation/Graph.hpp
===================================================================
--- src/Fragmentation/Graph.hpp	(revision 42127c3196b85e2b52749471ca9014640269b9fb)
+++ src/Fragmentation/Graph.hpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
@@ -15,4 +15,5 @@
 
 #include <map>
+#include <string>
 
 #include "Fragmentation/KeySet.hpp"
@@ -28,4 +29,11 @@
 
   void InsertGraph(Graph &graph, int *counter);
+
+  bool ParseKeySetFile(std::string &path);
+  bool StoreKeySetFile(std::string &path);
+  bool ParseTEFactorsFile(char *path);
+  bool StoreTEFactorsFile(char *path);
+
+  std::map<int,KeySet> * GraphToIndexedKeySet() const;
 };
 
Index: src/Fragmentation/KeySet.cpp
===================================================================
--- src/Fragmentation/KeySet.cpp	(revision 42127c3196b85e2b52749471ca9014640269b9fb)
+++ src/Fragmentation/KeySet.cpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
@@ -18,4 +18,8 @@
 
 #include "CodePatterns/MemDebug.hpp"
+
+#include <sstream>
+
+#include "CodePatterns/Log.hpp"
 
 #include "KeySet.hpp"
@@ -66,2 +70,27 @@
   return false; // if we reach this point, they are equal
 }
+
+/** Scans a single line for number and puts them into \a KeySet.
+ * \param *buffer buffer to scan
+ * \return true - at least one valid atom id parsed, false - CurrentSet is empty
+ */
+bool KeySet::ScanBufferIntoKeySet(char *buffer)
+{
+  std::stringstream line;
+  int AtomNr;
+  int status = 0;
+
+  line.str(buffer);
+  while (!line.eof()) {
+    line >> AtomNr;
+    if (AtomNr >= 0) {
+      insert(AtomNr);  // insert at end, hence in same order as in file!
+      status++;
+    } // else it's "-1" or else and thus must not be added
+  }
+  std::stringstream output;
+  for(KeySet::iterator runner = begin(); runner != end(); runner++)
+    output << (runner == begin() ? "" : " " ) << (*runner);
+  LOG(2, "INFO: The scanned KeySet is " << output.str());
+  return (status != 0);
+}
Index: src/Fragmentation/KeySet.hpp
===================================================================
--- src/Fragmentation/KeySet.hpp	(revision 42127c3196b85e2b52749471ca9014640269b9fb)
+++ src/Fragmentation/KeySet.hpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
@@ -23,4 +23,6 @@
 
   bool operator<(const KeySet &a) const;
+
+  bool ScanBufferIntoKeySet(char *buffer);
 };
 
Index: src/Fragmentation/fragmentation_helpers.cpp
===================================================================
--- src/Fragmentation/fragmentation_helpers.cpp	(revision 42127c3196b85e2b52749471ca9014640269b9fb)
+++ src/Fragmentation/fragmentation_helpers.cpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
@@ -36,214 +36,4 @@
 
 using namespace std;
-
-/** Scans a single line for number and puts them into \a KeySet.
- * \param *out output stream for debugging
- * \param *buffer buffer to scan
- * \param &CurrentSet filled KeySet on return
- * \return true - at least one valid atom id parsed, false - CurrentSet is empty
- */
-bool ScanBufferIntoKeySet(char *buffer, KeySet &CurrentSet)
-{
-  stringstream line;
-  int AtomNr;
-  int status = 0;
-
-  line.str(buffer);
-  while (!line.eof()) {
-    line >> AtomNr;
-    if (AtomNr >= 0) {
-      CurrentSet.insert(AtomNr);  // insert at end, hence in same order as in file!
-      status++;
-    } // else it's "-1" or else and thus must not be added
-  }
-  DoLog(1) && (Log() << Verbose(1) << "The scanned KeySet is ");
-  for(KeySet::iterator runner = CurrentSet.begin(); runner != CurrentSet.end(); runner++) {
-    DoLog(0) && (Log() << Verbose(0) << (*runner) << "\t");
-  }
-  DoLog(0) && (Log() << Verbose(0) << endl);
-  return (status != 0);
-};
-
-/** Parses the KeySet file and fills \a *FragmentList from the known molecule structure.
- * Does two-pass scanning:
- * -# Scans the keyset file and initialises a temporary graph
- * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
- * Finally, the temporary graph is inserted into the given \a FragmentList for return.
- * \param &path path to file
- * \param *FragmentList empty, filled on return
- * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
- */
-bool ParseKeySetFile(std::string &path, Graph *&FragmentList)
-{
-  bool status = true;
-  ifstream InputFile;
-  stringstream line;
-  GraphTestPair testGraphInsert;
-  int NumberOfFragments = 0;
-  string filename;
-
-  if (FragmentList == NULL) { // check list pointer
-    FragmentList = new Graph;
-  }
-
-  // 1st pass: open file and read
-  DoLog(1) && (Log() << Verbose(1) << "Parsing the KeySet file ... " << endl);
-  filename = path + KEYSETFILE;
-  InputFile.open(filename.c_str());
-  if (InputFile.good()) {
-    // each line represents a new fragment
-    char buffer[MAXSTRINGSIZE];
-    // 1. parse keysets and insert into temp. graph
-    while (!InputFile.eof()) {
-      InputFile.getline(buffer, MAXSTRINGSIZE);
-      KeySet CurrentSet;
-      if ((strlen(buffer) > 0) && (ScanBufferIntoKeySet(buffer, CurrentSet))) {  // if at least one valid atom was added, write config
-        testGraphInsert = FragmentList->insert(GraphPair (CurrentSet,pair<int,double>(NumberOfFragments++,1)));  // store fragment number and current factor
-        if (!testGraphInsert.second) {
-          DoeLog(0) && (eLog()<< Verbose(0) << "KeySet file must be corrupt as there are two equal key sets therein!" << endl);
-          performCriticalExit();
-        }
-      }
-    }
-    // 2. Free and done
-    InputFile.close();
-    InputFile.clear();
-    DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl);
-  } else {
-    DoLog(1) && (Log() << Verbose(1) << "\t ... File " << filename << " not found." << endl);
-    status = false;
-  }
-
-  return status;
-};
-
-/** Parses the TE factors file and fills \a *FragmentList from the known molecule structure.
- * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
- * \param *out output stream for debugging
- * \param *path path to file
- * \param *FragmentList graph whose nodes's TE factors are set on return
- * \return true - parsing successfully, false - failure on parsing
- */
-bool ParseTEFactorsFile(char *path, Graph *FragmentList)
-{
-  bool status = true;
-  ifstream InputFile;
-  stringstream line;
-  GraphTestPair testGraphInsert;
-  int NumberOfFragments = 0;
-  double TEFactor;
-  char filename[MAXSTRINGSIZE];
-
-  if (FragmentList == NULL) { // check list pointer
-    FragmentList = new Graph;
-  }
-
-  // 2nd pass: open TEFactors file and read
-  DoLog(1) && (Log() << Verbose(1) << "Parsing the TEFactors file ... " << endl);
-  sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, TEFACTORSFILE);
-  InputFile.open(filename);
-  if (InputFile != NULL) {
-    // 3. add found TEFactors to each keyset
-    NumberOfFragments = 0;
-    for(Graph::iterator runner = FragmentList->begin();runner != FragmentList->end(); runner++) {
-      if (!InputFile.eof()) {
-        InputFile >> TEFactor;
-        (*runner).second.second = TEFactor;
-        DoLog(2) && (Log() << Verbose(2) << "Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << "." << endl);
-      } else {
-        status = false;
-        break;
-      }
-    }
-    // 4. Free and done
-    InputFile.close();
-    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
-  } else {
-    DoLog(1) && (Log() << Verbose(1) << "File " << filename << " not found." << endl);
-    status = false;
-  }
-
-  return status;
-};
-
-/** Stores key sets to file.
- * \param KeySetList Graph with Keysets
- * \param &path path to file
- * \return true - file written successfully, false - writing failed
- */
-bool StoreKeySetFile(Graph &KeySetList, std::string &path)
-{
-  bool status =  true;
-  string line = path + KEYSETFILE;
-  ofstream output(line.c_str());
-
-  // open KeySet file
-  DoLog(1) && (Log() << Verbose(1) << "Saving key sets of the total graph ... ");
-  if(output.good()) {
-    for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) {
-      for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
-        if (sprinter != (*runner).first.begin())
-          output << "\t";
-        output << *sprinter;
-      }
-      output << endl;
-    }
-    DoLog(0) && (Log() << Verbose(0) << "done." << endl);
-  } else {
-    DoeLog(0) && (eLog()<< Verbose(0) << "Unable to open " << line << " for writing keysets!" << endl);
-    performCriticalExit();
-    status = false;
-  }
-  output.close();
-  output.clear();
-
-  return status;
-};
-
-
-/** Stores TEFactors to file.
- * \param *out output stream for debugging
- * \param KeySetList Graph with factors
- * \param *path path to file
- * \return true - file written successfully, false - writing failed
- */
-bool StoreTEFactorsFile(Graph &KeySetList, char *path)
-{
-  ofstream output;
-  bool status =  true;
-  string line;
-
-  // open TEFactors file
-  line = path;
-  line.append("/");
-  line += FRAGMENTPREFIX;
-  line += TEFACTORSFILE;
-  output.open(line.c_str(), ios::out);
-  DoLog(1) && (Log() << Verbose(1) << "Saving TEFactors of the total graph ... ");
-  if(output != NULL) {
-    for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++)
-      output << (*runner).second.second << endl;
-    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
-  } else {
-    DoLog(1) && (Log() << Verbose(1) << "failed to open " << line << "." << endl);
-    status = false;
-  }
-  output.close();
-
-  return status;
-};
-
-/** For a given graph, sorts KeySets into a (index, keyset) map.
- * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase
- * \return map from index to keyset
- */
-std::map<int,KeySet> * GraphToIndexedKeySet(Graph *GlobalKeySetList)
-{
-  map<int,KeySet> *IndexKeySetList = new map<int,KeySet>;
-  for(Graph::iterator runner = GlobalKeySetList->begin(); runner != GlobalKeySetList->end(); runner++) {
-    IndexKeySetList->insert( pair<int,KeySet>(runner->second.first,runner->first) );
-  }
-  return IndexKeySetList;
-};
 
 /** Inserts a (\a No, \a value) pair into the list, overwriting present one.
Index: src/Fragmentation/fragmentation_helpers.hpp
===================================================================
--- src/Fragmentation/fragmentation_helpers.hpp	(revision 42127c3196b85e2b52749471ca9014640269b9fb)
+++ src/Fragmentation/fragmentation_helpers.hpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
@@ -27,10 +27,4 @@
 class molecule;
 
-bool ScanBufferIntoKeySet(char *buffer, KeySet &CurrentSet);
-bool ParseKeySetFile(std::string &path, Graph *&FragmentList);
-bool ParseTEFactorsFile(char *path, Graph *FragmentList);
-bool StoreKeySetFile(Graph &KeySetList, std::string &path);
-bool StoreTEFactorsFile(Graph &KeySetList, char *path);
-std::map<int,KeySet> * GraphToIndexedKeySet(Graph *GlobalKeySetList);
 void InsertIntoAdaptiveCriteriaList(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, std::map<int,KeySet> &IndexKeySetList, int FragOrder, int No, double Value);
 int CountLinesinFile(std::ifstream &InputFile);
