Index: src/builder.cpp
===================================================================
--- src/builder.cpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/builder.cpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -1574,5 +1574,4 @@
                 int *MinimumRingSize = new int[mol->AtomCount];
                 atom ***ListOfLocalAtoms = NULL;
-                int FragmentCounter = 0;
                 class StackClass<bond *> *BackEdgeStack = NULL;
                 class StackClass<bond *> *LocalBackEdgeStack = NULL;
@@ -1580,16 +1579,18 @@
                 Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, BackEdgeStack);
                 if (Subgraphs != NULL) {
-                  Subgraphs->next->FillBondStructureFromReference((ofstream *)&cout, mol, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
+                  int FragmentCounter = 0;
                   while (Subgraphs->next != NULL) {
                     Subgraphs = Subgraphs->next;
+                    Subgraphs->FillBondStructureFromReference((ofstream *)&cout, mol, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
                     LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
-                    Subgraphs->Leaf->PickLocalBackEdges((ofstream *)&cout, ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack);
-                    Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, BackEdgeStack, MinimumRingSize);
+                    Subgraphs->Leaf->PickLocalBackEdges((ofstream *)&cout, ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack);
+                    Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, LocalBackEdgeStack, MinimumRingSize);
                     delete(LocalBackEdgeStack);
                     delete(Subgraphs->previous);
+                    FragmentCounter++;
                   }
                   delete(Subgraphs);
                   for (int i=0;i<FragmentCounter;i++)
-                    Free(&ListOfLocalAtoms[FragmentCounter]);
+                    Free(&ListOfLocalAtoms[i]);
                   Free(&ListOfLocalAtoms);
                 }
@@ -2115,30 +2116,15 @@
   switch(j) {
     case 255:  // something went wrong
+    case 2:  // just for -f option
+    case 1:  // just for -v and -h options
       delete(molecules); // also free's all molecules contained
       delete(periode);
+      delete(configuration);
       cout << Verbose(0) <<  "Maximum of allocated memory: "
         << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
       cout << Verbose(0) <<  "Remaining non-freed memory: "
         << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
-     return j;
-      break;
-    case 1:  // just for -v and -h options
-      delete(molecules); // also free's all molecules contained
-      delete(periode);
-      cout << Verbose(0) <<  "Maximum of allocated memory: "
-        << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
-      cout << Verbose(0) <<  "Remaining non-freed memory: "
-        << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
-      return 0;
-      break;
-    case 2:  // just for -f option
-      delete(molecules); // also free's all molecules contained
-      delete(periode);
-      cout << Verbose(0) <<  "Maximum of allocated memory: "
-        << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
-      cout << Verbose(0) <<  "Remaining non-freed memory: "
-        << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
-      return 2;
-      break;
+      MemoryUsageObserver::getInstance()->purgeInstance();
+     return (j == 1 ? 0 : j);
     default:
       break;
@@ -2155,4 +2141,5 @@
       }
     }
+    mol->ActiveFlag = true;
     molecules->insert(mol);
   }
Index: src/config.cpp
===================================================================
--- src/config.cpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/config.cpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -199,4 +199,6 @@
     Free(&ThermostatNames[j]);
   Free(&ThermostatNames);
+  if (BG != NULL)
+    delete(BG);
 };
 
Index: src/helpers.hpp
===================================================================
--- src/helpers.hpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/helpers.hpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -98,6 +98,6 @@
   }
 
-  // allocat and fill
-  LookupTable = Malloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
+  // allocate and fill
+  LookupTable = Calloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
   if (LookupTable == NULL) {
     cerr << "LookupTable memory allocation failed!" << endl;
Index: src/memoryallocator.hpp
===================================================================
--- src/memoryallocator.hpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/memoryallocator.hpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -55,5 +55,5 @@
 template <> char* Malloc<char>(size_t size, const char* output);
 
-/** Allocates a memory range using calloc().
+/* Allocates a memory range using calloc().
  * Prints the provided error message in case of a failure.
  *
@@ -61,9 +61,9 @@
  * \param failure message which is printed if the allocation fails
  * \return pointer to the allocated memory range, will be NULL if a failure occurred
- */
+*/
 template <typename X> X* Calloc(size_t size, const char* output)
 {
   X* buffer = NULL;
-  buffer = (X*) calloc(sizeof(X) * size, (size_t) 0);
+  buffer = (X*) calloc(size, sizeof(X));
 
   if (buffer != NULL) {
@@ -76,4 +76,5 @@
   return buffer;
 };
+
 
 /** Reallocates a memory range using realloc(). If the provided pointer to the old
Index: src/memoryusageobserver.cpp
===================================================================
--- src/memoryusageobserver.cpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/memoryusageobserver.cpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -23,5 +23,7 @@
  */
 MemoryUsageObserver::~MemoryUsageObserver() {
-  for (map<void*, size_t>::iterator current = memoryUsers.begin(); current != memoryUsers.end(); current++) {
+  while (!memoryUsers.empty()) {
+    map<void*, size_t>::iterator current = memoryUsers.begin();
+    free(current->first);
     memoryUsers.erase(current);
   }
Index: src/molecule.cpp
===================================================================
--- src/molecule.cpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/molecule.cpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -957,6 +957,6 @@
   if (result) {
     *out << Verbose(5) << "Calculating distances" << endl;
-    Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
-    OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
+    Distances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
+    OtherDistances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
     SetIndexedArrayForEachAtomTo ( Distances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity);
     SetIndexedArrayForEachAtomTo ( OtherDistances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity);
@@ -964,9 +964,9 @@
     /// ... sort each list (using heapsort (o(N log N)) from GSL)
     *out << Verbose(5) << "Sorting distances" << endl;
-    PermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
-    OtherPermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
+    PermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
+    OtherPermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
     gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles);
     gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);
-    PermutationMap = Malloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
+    PermutationMap = Calloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     *out << Verbose(5) << "Combining Permutation Maps" << endl;
     for(int i=AtomCount;i--;)
Index: src/molecule_dynamics.cpp
===================================================================
--- src/molecule_dynamics.cpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/molecule_dynamics.cpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -193,8 +193,6 @@
 {
   stringstream zeile1, zeile2;
-  int *DoubleList = Malloc<int>(AtomCount, "PrintPermutationMap: *DoubleList");
+  int *DoubleList = Calloc<int>(AtomCount, "PrintPermutationMap: *DoubleList");
   int doubles = 0;
-  for (int i=0;i<AtomCount;i++)
-    DoubleList[i] = 0;
   zeile1 << "PermutationMap: ";
   zeile2 << "                ";
@@ -243,7 +241,4 @@
 void CreateInitialLists(ofstream *out, molecule *mol, struct EvaluatePotential &Params)
 {
-  for (int i=mol->AtomCount; i--;)
-    Params.DoubleList[i] = 0;  // stores for how many atoms in startstep this atom is a target in endstep
-
   atom *Walker = mol->start;
   while (Walker->next != mol->end) {
@@ -347,8 +342,8 @@
   double Potential, OldPotential, OlderPotential;
   struct EvaluatePotential Params;
-  Params.PermutationMap = Malloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**PermutationMap");
+  Params.PermutationMap = Calloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**PermutationMap");
   Params.DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**DistanceList");
   Params.DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DistanceIterators");
-  Params.DoubleList = Malloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DoubleList");
+  Params.DoubleList = Calloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DoubleList");
   Params.StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*StepList");
   int round;
Index: src/molecule_fragmentation.cpp
===================================================================
--- src/molecule_fragmentation.cpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/molecule_fragmentation.cpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -123,4 +123,5 @@
   }
 
+  Free(&filename);
   return status;
 };
@@ -574,6 +575,5 @@
   // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
   Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack);
-  // fill the bond structure of the individually stored subgraphs
-  Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
+
   // analysis of the cycles (print rings, get minimum cycle length) for each subgraph
   for(int i=AtomCount;i--;)
@@ -583,4 +583,6 @@
   while (MolecularWalker->next != NULL) {
     MolecularWalker = MolecularWalker->next;
+    // fill the bond structure of the individually stored subgraphs
+  MolecularWalker->FillBondStructureFromReference(out, this, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
     *out << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl;
     LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount);
@@ -599,4 +601,5 @@
     delete(LocalBackEdgeStack);
   }
+  delete(BackEdgeStack);
 
   // ===== 3. if structure still valid, parse key set file and others =====
@@ -663,52 +666,52 @@
   // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
   //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
-    // allocate memory for the pointer array and transmorph graphs into full molecular fragments
-    BondFragments = new MoleculeListClass();
-    int k=0;
-    for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
-      KeySet test = (*runner).first;
-      *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;
-      BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration));
-      k++;
-    }
-    *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl;
-
-    // ===== 9. Save fragments' configuration and keyset files et al to disk ===
-    if (BondFragments->ListOfMolecules.size() != 0) {
-      // create the SortIndex from BFS labels to order in the config file
-      CreateMappingLabelsToConfigSequence(out, SortIndex);
-
-      *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl;
-      if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))
-        *out << Verbose(1) << "All configs written." << endl;
-      else
-        *out << Verbose(1) << "Some config writing failed." << endl;
-
-      // store force index reference file
-      BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex);
-
-      // store keysets file
-      StoreKeySetFile(out, TotalGraph, configuration->configpath);
-
-      // store Adjacency file
-      StoreAdjacencyToFile(out, configuration->configpath);
-
-      // store Hydrogen saturation correction file
-      BondFragments->AddHydrogenCorrection(out, configuration->configpath);
-
-      // store adaptive orders into file
-      StoreOrderAtSiteFile(out, configuration->configpath);
-
-      // restore orbital and Stop values
-      CalculateOrbitals(*configuration);
-
-      // free memory for bond part
-      *out << Verbose(1) << "Freeing bond memory" << endl;
-      delete(FragmentList); // remove bond molecule from memory
-      Free(&SortIndex);
-    } else
-      *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
-  //} else
-  //  *out << Verbose(1) << "No fragments to store." << endl;
+  // allocate memory for the pointer array and transmorph graphs into full molecular fragments
+  BondFragments = new MoleculeListClass();
+  int k=0;
+  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
+    KeySet test = (*runner).first;
+    *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;
+    BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration));
+    k++;
+  }
+  *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl;
+
+  // ===== 9. Save fragments' configuration and keyset files et al to disk ===
+  if (BondFragments->ListOfMolecules.size() != 0) {
+    // create the SortIndex from BFS labels to order in the config file
+    CreateMappingLabelsToConfigSequence(out, SortIndex);
+
+    *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl;
+    if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))
+      *out << Verbose(1) << "All configs written." << endl;
+    else
+      *out << Verbose(1) << "Some config writing failed." << endl;
+
+    // store force index reference file
+    BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex);
+
+    // store keysets file
+    StoreKeySetFile(out, TotalGraph, configuration->configpath);
+
+    // store Adjacency file
+    StoreAdjacencyToFile(out, configuration->configpath);
+
+    // store Hydrogen saturation correction file
+    BondFragments->AddHydrogenCorrection(out, configuration->configpath);
+
+    // store adaptive orders into file
+    StoreOrderAtSiteFile(out, configuration->configpath);
+
+    // restore orbital and Stop values
+    CalculateOrbitals(*configuration);
+
+    // free memory for bond part
+    *out << Verbose(1) << "Freeing bond memory" << endl;
+    delete(FragmentList); // remove bond molecule from memory
+    Free(&SortIndex);
+  } else {
+    *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
+  }
+  delete(BondFragments);
   *out << Verbose(0) << "End of bond fragmentation." << endl;
 
@@ -751,6 +754,6 @@
 bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path)
 {
-  unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
-  bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
+  unsigned char *OrderArray = Calloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
+  bool *MaxArray = Calloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
   bool status;
   int AtomNr, value;
@@ -759,13 +762,7 @@
 
   *out << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl;
-  for(int i=AtomCount;i--;)
-    OrderArray[i] = 0;
   line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
   file.open(line.str().c_str());
   if (file != NULL) {
-    for (int i=AtomCount;i--;) { // initialise with 0
-      OrderArray[i] = 0;
-      MaxArray[i] = 0;
-    }
     while (!file.eof()) { // parse from file
       AtomNr = -1;
@@ -830,5 +827,5 @@
  * \param *Leaf fragment molecule
  * \param &Leaflet pointer to KeySet structure
- * \param **SonList list which atom of \a *Leaf is a son of which atom in \a *mol
+ * \param **SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
  * \return number of atoms in fragment
  */
@@ -840,8 +837,4 @@
   for(int i=NDIM*2;i--;)
     Leaf->cell_size[i] = mol->cell_size[i];
-
-  // initialise SonList (indicates when we need to replace a bond with hydrogen instead)
-  for(int i=mol->AtomCount;i--;)
-    SonList[i] = NULL;
 
   // first create the minimal set of atoms from the KeySet
@@ -924,5 +917,5 @@
 molecule * molecule::StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem)
 {
-  atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
+  atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
   molecule *Leaf = new molecule(elemente);
 
@@ -1389,5 +1382,5 @@
 
     // prepare the subset and call the generator
-    BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
+    BondsList = Calloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
 
@@ -1544,12 +1537,12 @@
   // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
   // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5)
-  NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
-  FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
+  NumMoleculesOfOrder = Calloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
+  FragmentLowerOrdersList = Calloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
 
   // initialise the fragments structure
-  FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
   FragmentSearch.FragmentCounter = 0;
   FragmentSearch.FragmentSet = new KeySet;
   FragmentSearch.Root = FindAtom(RootKeyNr);
+  FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
   for (int i=AtomCount;i--;) {
     FragmentSearch.ShortestPathList[i] = -1;
@@ -1587,7 +1580,5 @@
       // allocate memory for all lower level orders in this 1D-array of ptrs
       NumLevels = 1 << (Order-1); // (int)pow(2,Order);
-      FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
-      for (int i=0;i<NumLevels;i++)
-        FragmentLowerOrdersList[RootNr][i] = NULL;
+      FragmentLowerOrdersList[RootNr] = Calloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
 
       // create top order where nothing is reduced
@@ -1665,5 +1656,5 @@
   *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl;
 
-  ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
+  ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
   while (flag) {
     // remove bonds that are beyond bonddistance
Index: src/molecule_graph.cpp
===================================================================
--- src/molecule_graph.cpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/molecule_graph.cpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -126,5 +126,5 @@
 
     // create a list to map Tesselpoint::nr to atom *
-    AtomMap = Malloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
+    AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
     Walker = start;
     while (Walker->next != end) {
@@ -437,13 +437,16 @@
  * \param *out output stream for debugging
  * \param &DFS accounting structure to allocate
- * \param AtomCount number of nodes in graph
- * \param BondCount number of edges in graph
- */
-void DepthFirstSearchAnalysis_Init(ofstream *out, struct DFSAccounting &DFS, int AtomCount, int BondCount)
-{
-  DFS.AtomStack = new StackClass<atom *> (AtomCount);
+ * \param *mol molecule with AtomCount, BondCount and all atoms
+ */
+void DepthFirstSearchAnalysis_Init(ofstream *out, struct DFSAccounting &DFS, const molecule * const mol)
+{
+  DFS.AtomStack = new StackClass<atom *> (mol->AtomCount);
   DFS.CurrentGraphNr = 0;
   DFS.ComponentNumber = 0;
   DFS.BackStepping = false;
+  mol->ResetAllBondsToUnused();
+  mol->SetAtomValueToValue(-1, &atom::GraphNr);
+  mol->ActOnAllAtoms(&atom::InitComponentNr);
+  DFS.BackEdgeStack->ClearStack();
 }
 ;
@@ -456,4 +459,5 @@
 {
   delete (DFS.AtomStack);
+  // delete (DFS.BackEdgeStack); // DON'T free, see DepthFirstSearchAnalysis(), is returned as allocated
 }
 ;
@@ -479,13 +483,9 @@
 
   *out << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl;
-  DepthFirstSearchAnalysis_Init(out, DFS, AtomCount, BondCount);
+  DepthFirstSearchAnalysis_Init(out, DFS, this);
+
   DFS.Root = start->next;
-
-  ResetAllBondsToUnused();
-  SetAtomValueToValue(-1, &atom::GraphNr);
-  ActOnAllAtoms(&atom::InitComponentNr);
-  DFS.BackEdgeStack->ClearStack();
   while (DFS.Root != end) { // if there any atoms at all
-    // (1) mark all edges unused, empty stack, set atom->GraphNr = 0 for all
+    // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all
     DFS.AtomStack->ClearStack();
 
@@ -602,14 +602,11 @@
 {
   BFS.AtomCount = AtomCount;
-  BFS.PredecessorList = Malloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
+  BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
   BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
-  BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
+  BFS.ColorList = Calloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
   BFS.BFSStack = new StackClass<atom *> (AtomCount);
 
-  for (int i = AtomCount; i--;) {
-    BFS.PredecessorList[i] = NULL;
+  for (int i = AtomCount; i--;)
     BFS.ShortestPathList[i] = -1;
-    BFS.ColorList[i] = white;
-  }
 };
 
@@ -1002,5 +999,5 @@
 
   // allocate storage structure
-  CurrentBonds = Malloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
+  CurrentBonds = Calloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
   return true;
 }
@@ -1137,6 +1134,6 @@
   BFS.AtomCount = AtomCount;
   BFS.BondOrder = BondOrder;
-  BFS.PredecessorList = Malloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
-  BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
+  BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
+  BFS.ShortestPathList = Calloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
   BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
   BFS.BFSStack = new StackClass<atom *> (AtomCount);
@@ -1148,5 +1145,4 @@
   // initialise each vertex as white with no predecessor, empty queue, color Root lightgray
   for (int i = AtomCount; i--;) {
-    BFS.PredecessorList[i] = NULL;
     BFS.ShortestPathList[i] = -1;
     if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited
@@ -1155,5 +1151,5 @@
       BFS.ColorList[i] = white;
   }
-  BFS.ShortestPathList[Root->nr] = 0;
+  //BFS.ShortestPathList[Root->nr] = 0; //is set due to Calloc()
 }
 ;
@@ -1302,8 +1298,6 @@
 {
   // reset parent list
-  ParentList = Malloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
+  ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
   *out << Verbose(3) << "Resetting ParentList." << endl;
-  for (int i = AtomCount; i--;)
-    ParentList[i] = NULL;
 }
 ;
Index: src/moleculelist.cpp
===================================================================
--- src/moleculelist.cpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/moleculelist.cpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -422,9 +422,9 @@
 
   // 0b. allocate memory for constants
-  FitConstant = Malloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
+  FitConstant = Calloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
   for (int k = 0; k < 3; k++) {
-    FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
+    FitConstant[k] = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     for (int i = a; i--;) {
-      FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
+      FitConstant[k][i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
     }
   }
@@ -471,7 +471,7 @@
 
   // 0d. allocate final correction matrix
-  correction = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");
+  correction = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");
   for (int i = a; i--;)
-    correction[i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
+    correction[i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
 
   // 1a. go through every molecule in the list
@@ -548,11 +548,11 @@
   output.close();
   // 6. free memory of parsed matrices
-  FitConstant = Malloc<double**>(a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
   for (int k = 0; k < 3; k++) {
-    FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     for (int i = a; i--;) {
-      FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
-    }
-  }
+      Free(&FitConstant[k][i]);
+    }
+    Free(&FitConstant[k]);
+  }
+  Free(&FitConstant);
   cout << "done." << endl;
   return true;
@@ -712,6 +712,5 @@
     //outputFragment.close();
     //outputFragment.clear();
-    delete (FragmentNumber);
-    //Free(&FragmentNumber);
+    Free(&FragmentNumber);
   }
   cout << " done." << endl;
@@ -848,8 +847,8 @@
       }
     }
-    FragmentCounter++;
-    if (next != NULL)
-      status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms);
-    FragmentCounter--;
+//    FragmentCounter++;
+//    if (next != NULL)
+//      status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms);
+//    FragmentCounter--;
   }
 
@@ -860,5 +859,4 @@
       Free(&ListOfLocalAtoms);
   }
-  FragmentCounter--;
   *out << Verbose(1) << "End of FillBondStructureFromReference." << endl;
   return status;
@@ -907,10 +905,10 @@
 
 /** Fills a lookup list of father's Atom::nr -> atom for each subgraph.
- * \param *out output stream fro debugging
+ * \param *out output stream from debugging
  * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
  * \param FragmentCounter counts the fragments as we move along the list
  * \param GlobalAtomCount number of atoms in the complete molecule
  * \param &FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
- * \return true - succes, false - failure
+ * \return true - success, false - failure
  */
 bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList)
@@ -921,8 +919,6 @@
   if (ListOfLocalAtoms == NULL) { // allocated initial pointer
     // allocate and set each field to NULL
-    ListOfLocalAtoms = Malloc<atom**>(Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
+    ListOfLocalAtoms = Calloc<atom**>(Counter, "MoleculeLeafClass::FillListOfLocalAtoms - ***ListOfLocalAtoms");
     if (ListOfLocalAtoms != NULL) {
-      for (int i = Counter; i--;)
-        ListOfLocalAtoms[i] = NULL;
       FreeList = FreeList && true;
     } else
@@ -965,7 +961,5 @@
   if (FragmentList == NULL) {
     KeySetCounter = Count();
-    FragmentList = Malloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
-    for (int i = KeySetCounter; i--;)
-      FragmentList[i] = NULL;
+    FragmentList = Calloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
     KeySetCounter = 0;
   }
Index: src/stackclass.hpp
===================================================================
--- src/stackclass.hpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/stackclass.hpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -48,7 +48,7 @@
 /** Constructor of class StackClass.
  */
-template <typename T> StackClass<T>::StackClass(int dimension) : EntryCount(dimension), CurrentLastEntry(0), CurrentFirstEntry(0), NextFreeField(0)
-{
-  StackList = Malloc<T>(EntryCount, "StackClass::StackClass: **StackList");
+template <typename T> StackClass<T>::StackClass(int dimension) : StackList(NULL), EntryCount(dimension), CurrentLastEntry(0), CurrentFirstEntry(0), NextFreeField(0)
+{
+  StackList = Calloc<T>(EntryCount, "StackClass::StackClass: **StackList");
 };
 
Index: src/unittests/memoryallocatorunittest.cpp
===================================================================
--- src/unittests/memoryallocatorunittest.cpp	(revision fa649a93ddcddda5f2e4f18ee89b49c4d34d2fde)
+++ src/unittests/memoryallocatorunittest.cpp	(revision 7218f8e00e4f8e7b2a82385c86479318f7b29c7b)
@@ -28,4 +28,5 @@
 void MemoryAllocatorTest::tearDown()
 {
+  MemoryUsageObserver::getInstance()->purgeInstance();
 };
 
@@ -49,5 +50,7 @@
 
   char** buffer4 = NULL;
-  buffer4 = Malloc<char*>(1, "");
+  buffer4 = Malloc<char*>(10, "");
+  for (int i=0;i<10;i++)
+    buffer4[i] = NULL;
   Free(&buffer4);
 };
@@ -59,13 +62,15 @@
 {
   int* buffer1 = NULL;
-  buffer1 = Calloc<int>(1, "");
+  buffer1 = Calloc<int>(10, "");
   Free(&buffer1);
 
   long* buffer2 = NULL;
-  buffer2 = Calloc<long>(1, "");
+  buffer2 = Calloc<long>(10, "");
   Free(&buffer2);
 
-  char* buffer3 = NULL;
-  buffer3 = Calloc<char>(1, "");
+  char** buffer3 = NULL;
+  buffer3 = Calloc<char *>(10, "");
+  for (int i=0;i<10;i++)
+    buffer3[i] = NULL;
   Free(&buffer3);
 };
