Index: src/molecules.cpp
===================================================================
--- src/molecules.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/molecules.cpp	(revision 41194a7bf06101702d6e0b8243fa47ade9e8c24e)
@@ -6,4 +6,5 @@
 
 #include "config.hpp"
+#include "memoryallocator.hpp"
 #include "molecules.hpp"
 
@@ -55,7 +56,7 @@
   if (ListOfBondsPerAtom != NULL)
     for(int i=AtomCount;i--;)
-      Free((void **)&ListOfBondsPerAtom[i], "molecule::~molecule: ListOfBondsPerAtom[i]");
-  Free((void **)&ListOfBondsPerAtom, "molecule::~molecule: ListOfBondsPerAtom");
-  Free((void **)&NumberOfBondsPerAtom, "molecule::~molecule: NumberOfBondsPerAtom");
+      Free(&ListOfBondsPerAtom[i]);
+  Free(&ListOfBondsPerAtom);
+  Free(&NumberOfBondsPerAtom);
   if (TesselStruct != NULL)
     delete(TesselStruct);
@@ -163,6 +164,6 @@
         NoNonHydrogen++;
       if (pointer->Name == NULL) {
-        Free((void **)&pointer->Name, "molecule::AddAtom: *pointer->Name");
-        pointer->Name = (char *) Malloc(sizeof(char)*6, "molecule::AddAtom: *pointer->Name");
+        Free(&pointer->Name);
+        pointer->Name = Malloc<char>(6, "molecule::AddAtom: *pointer->Name");
         sprintf(pointer->Name, "%2s%02d", pointer->type->symbol, pointer->nr+1);
       }
@@ -182,5 +183,5 @@
   if (pointer != NULL) {
     atom *walker = new atom(pointer);
-    walker->Name = (char *) Malloc(sizeof(char)*strlen(pointer->Name)+1, "atom::atom: *Name");
+    walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
     strcpy (walker->Name, pointer->Name);
     walker->nr = last_atom++;  // increase number within molecule
@@ -267,5 +268,5 @@
     Orthovector1.MatrixMultiplication(matrix);
     InBondvector.SubtractVector(&Orthovector1); // subtract just the additional translation
-    Free((void **)&matrix, "molecule::AddHydrogenReplacementAtom: *matrix");
+    Free(&matrix);
     bondlength = InBondvector.Norm();
 //    *out << Verbose(4) << "Corrected InBondvector is now: ";
@@ -1080,5 +1081,5 @@
     }
   } while (!flag);
-  Free((void **)&matrix, "molecule::DetermineCenter: *matrix");
+  Free(&matrix);
   Center.Scale(1./(double)AtomCount);
 };
@@ -1339,5 +1340,5 @@
 {
   stringstream zeile1, zeile2;
-  int *DoubleList = (int *) Malloc(Nr*sizeof(int), "PrintPermutationMap: *DoubleList");
+  int *DoubleList = Malloc<int>(Nr, "PrintPermutationMap: *DoubleList");
   int doubles = 0;
   for (int i=0;i<Nr;i++)
@@ -1354,5 +1355,5 @@
     doubles++;
  // *out << "Found " << doubles << " Doubles." << endl;
-  Free((void **)&DoubleList, "PrintPermutationMap: *DoubleList");
+  Free(&DoubleList);
 //  *out << zeile1.str() << endl << zeile2.str() << endl;
 };
@@ -1388,9 +1389,9 @@
 {
   double Potential, OldPotential, OlderPotential;
-  PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::MinimiseConstrainedPotential: **PermutationMap");
-  DistanceMap **DistanceList = (DistanceMap **) Malloc(AtomCount*sizeof(DistanceMap *), "molecule::MinimiseConstrainedPotential: **DistanceList");
-  DistanceMap::iterator *DistanceIterators = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *DistanceIterators");
-  int *DoubleList = (int *) Malloc(AtomCount*sizeof(int), "molecule::MinimiseConstrainedPotential: *DoubleList");
-  DistanceMap::iterator *StepList = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *StepList");
+  PermutationMap = Malloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: **PermutationMap");
+  DistanceMap **DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: **DistanceList");
+  DistanceMap::iterator *DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *DistanceIterators");
+  int *DoubleList = Malloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: *DoubleList");
+  DistanceMap::iterator *StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *StepList");
   double constants[3];
   int round;
@@ -1468,5 +1469,5 @@
     }
   *out << Verbose(1) << "done." << endl;
-  Free((void **)&DoubleList, "molecule::MinimiseConstrainedPotential: *DoubleList");
+  Free(&DoubleList);
   // argument minimise the constrained potential in this injective PermutationMap
   *out << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl;
@@ -1549,6 +1550,6 @@
   for (int i=AtomCount; i--;)
     DistanceList[i]->clear();
-  Free((void **)&DistanceList, "molecule::MinimiseConstrainedPotential: **DistanceList");
-  Free((void **)&DistanceIterators, "molecule::MinimiseConstrainedPotential: *DistanceIterators");
+  Free(&DistanceList);
+  Free(&DistanceIterators);
   return ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem);
 };
@@ -1647,5 +1648,5 @@
   
   // store the list to single step files
-  int *SortIndex = (int *) Malloc(AtomCount*sizeof(int), "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
+  int *SortIndex = Malloc<int>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
   for (int i=AtomCount; i--; )
     SortIndex[i] = i;
@@ -1653,5 +1654,5 @@
   
   // free and return
-  Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
+  Free(&PermutationMap);
   delete(MoleculePerStep);
   return status;
@@ -1712,5 +1713,5 @@
       ConstrainedPotentialEnergy = MinimiseConstrainedPotential(out, PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem());
       EvaluateConstrainedForces(out, configuration.DoConstrainedMD, 0, PermutationMap, &Force);
-      Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
+      Free(&PermutationMap);
     }
     
@@ -2412,6 +2413,6 @@
         if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it
           NoNonHydrogen++;
-        Free((void **)&Walker->Name, "molecule::CountAtoms: *walker->Name");
-        Walker->Name = (char *) Malloc(sizeof(char)*6, "molecule::CountAtoms: *walker->Name");
+        Free(&Walker->Name);
+        Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
         sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);
         *out << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;
@@ -2624,5 +2625,5 @@
     NumberCells = divisor[0]*divisor[1]*divisor[2];
     *out << Verbose(1) << "Allocating " << NumberCells << " cells." << endl;
-    CellList = (molecule **) Malloc(sizeof(molecule *)*NumberCells, "molecule::CreateAdjacencyList - ** CellList");
+    CellList = Malloc<molecule*>(NumberCells, "molecule::CreateAdjacencyList - ** CellList");
     for (int i=NumberCells;i--;)
       CellList[i] = NULL;
@@ -2706,5 +2707,5 @@
         delete(CellList[i]);
       }
-    Free((void **)&CellList, "molecule::CreateAdjacencyList - ** CellList");
+    Free(&CellList);
 
     // create the adjacency list per atom
@@ -2771,5 +2772,5 @@
     *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
   *out << Verbose(0) << "End of CreateAdjacencyList." << endl;
-  Free((void **)&matrix, "molecule::CreateAdjacencyList: *matrix");
+  Free(&matrix);
 
 };
@@ -2981,7 +2982,7 @@
 void molecule::CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *  BackEdgeStack, int *&MinimumRingSize)
 {
-  atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::CyclicStructureAnalysis: **PredecessorList");
-  int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList");
-  enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CyclicStructureAnalysis: *ColorList");
+  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CyclicStructureAnalysis: **PredecessorList");
+  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList");
+  enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::CyclicStructureAnalysis: *ColorList");
   class StackClass<atom *> *BFSStack = new StackClass<atom *> (AtomCount);   // will hold the current ring
   class StackClass<atom *> *TouchedStack = new StackClass<atom *> (AtomCount);   // contains all "touched" atoms (that need to be reset after BFS loop)
@@ -3174,7 +3175,7 @@
     *out << Verbose(1) << "No rings were detected in the molecular structure." << endl;
 
-  Free((void **)&PredecessorList, "molecule::CyclicStructureAnalysis: **PredecessorList");
-  Free((void **)&ShortestPathList, "molecule::CyclicStructureAnalysis: **ShortestPathList");
-  Free((void **)&ColorList, "molecule::CyclicStructureAnalysis: **ColorList");
+  Free(&PredecessorList);
+  Free(&ShortestPathList);
+  Free(&ColorList);
   delete(BFSStack);
 };
@@ -3220,6 +3221,6 @@
     Walker = Walker->next;
     if (Walker->ComponentNr != NULL)
-      Free((void **)&Walker->ComponentNr, "molecule::InitComponentNumbers: **Walker->ComponentNr");
-    Walker->ComponentNr = (int *) Malloc(sizeof(int)*NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
+      Free(&Walker->ComponentNr);
+    Walker->ComponentNr = Malloc<int>(NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
     for (int i=NumberOfBondsPerAtom[Walker->nr];i--;)
       Walker->ComponentNr[i] = -1;
@@ -3344,5 +3345,5 @@
   int NumberOfFragments = 0;
   double TEFactor;
-  char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
+  char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
 
   if (FragmentList == NULL) { // check list pointer
@@ -3356,5 +3357,5 @@
   if (InputFile != NULL) {
     // each line represents a new fragment
-    char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
+    char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
     // 1. parse keysets and insert into temp. graph
     while (!InputFile.eof()) {
@@ -3371,5 +3372,5 @@
     InputFile.close();
     InputFile.clear();
-    Free((void **)&buffer, "molecule::ParseKeySetFile - *buffer");
+    Free(&buffer);
     *out << Verbose(1) << "done." << endl;
   } else {
@@ -3404,5 +3405,5 @@
 
   // free memory
-  Free((void **)&filename, "molecule::ParseKeySetFile - filename");
+  Free(&filename);
 
   return status;
@@ -3511,5 +3512,5 @@
   stringstream filename;
   bool status = true;
-  char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
+  char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
 
   filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
@@ -3519,5 +3520,5 @@
     // allocate storage structure
     int NonMatchNumber = 0;   // will number of atoms with differing bond structure
-    int *CurrentBonds = (int *) Malloc(sizeof(int)*8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
+    int *CurrentBonds = Malloc<int>(8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
     int CurrentBondsOfAtom;
 
@@ -3564,5 +3565,5 @@
     } else
       *out << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl;
-    Free((void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds");
+    Free(&CurrentBonds);
   } else {
     *out << Verbose(1) << "Adjacency file not found." << endl;
@@ -3570,5 +3571,5 @@
   }
   *out << endl;
-  Free((void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
+  Free(&buffer);
 
   return status;
@@ -3598,5 +3599,5 @@
       return false;
     // parse the EnergyPerFragment file
-    char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
+    char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
     sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT);
     InputFile.open(buffer, ios::in);
@@ -3705,5 +3706,5 @@
       }
     }
-    Free((void **)&buffer, "molecule::CheckOrderAtSite: *buffer");
+    Free(&buffer);
     // pick a given number of highest values and set AtomMask
   } else { // global increase of Bond Order
@@ -3757,5 +3758,5 @@
     return false;
   }
-  SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex");
+  SortIndex = Malloc<int>(AtomCount, "molecule::FragmentMolecule: *SortIndex");
   for(int i=AtomCount;i--;)
     SortIndex[i] = -1;
@@ -3831,5 +3832,5 @@
   // === compare it with adjacency file ===
   FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms);
-  Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");
+  Free(&ListOfAtoms);
 
   // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
@@ -3920,5 +3921,5 @@
     delete(Subgraphs);
   }
-  Free((void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");
+  Free(&FragmentList);
 
   // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
@@ -3967,5 +3968,5 @@
       *out << Verbose(1) << "Freeing bond memory" << endl;
       delete(FragmentList); // remove bond molecule from memory
-      Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");
+      Free(&SortIndex);
     } else
       *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
@@ -4055,6 +4056,6 @@
 bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path)
 {
-  unsigned char *OrderArray = (unsigned char *) Malloc(sizeof(unsigned char)*AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
-  bool *MaxArray = (bool *) Malloc(sizeof(bool)*AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
+  unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
+  bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
   bool status;
   int AtomNr, value;
@@ -4097,6 +4098,6 @@
     status = false;
   }
-  Free((void **)&OrderArray, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
-  Free((void **)&MaxArray, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
+  Free(&OrderArray);
+  Free(&MaxArray);
 
   *out << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl;
@@ -4121,11 +4122,11 @@
   if (ListOfBondsPerAtom != NULL) {
     for(int i=AtomCount;i--;)
-      Free((void **)&ListOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom[i]");
-    Free((void **)&ListOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom");
+      Free(&ListOfBondsPerAtom[i]);
+    Free(&ListOfBondsPerAtom);
   }
   if (NumberOfBondsPerAtom != NULL)
-    Free((void **)&NumberOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: NumberOfBondsPerAtom");
-  ListOfBondsPerAtom = (bond ***) Malloc(sizeof(bond **)*AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom");
-  NumberOfBondsPerAtom = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom");
+    Free(&NumberOfBondsPerAtom);
+  ListOfBondsPerAtom = Malloc<bond**>(AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom");
+  NumberOfBondsPerAtom = Malloc<int>(AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom");
 
   // reset bond counts per atom
@@ -4141,5 +4142,5 @@
   for(int i=AtomCount;i--;) {
     // allocate list of bonds per atom
-    ListOfBondsPerAtom[i] = (bond **) Malloc(sizeof(bond *)*NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
+    ListOfBondsPerAtom[i] = Malloc<bond*>(NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
     // clear the list again, now each NumberOfBondsPerAtom marks current free field
     NumberOfBondsPerAtom[i] = 0;
@@ -4183,7 +4184,7 @@
 void molecule::BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem)
 {
-  atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::BreadthFirstSearchAdd: **PredecessorList");
-  int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList");
-  enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList");
+  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::BreadthFirstSearchAdd: **PredecessorList");
+  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList");
+  enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList");
   class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount);
   atom *Walker = NULL, *OtherAtom = NULL;
@@ -4290,7 +4291,7 @@
     *out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
   }
-  Free((void **)&PredecessorList, "molecule::BreadthFirstSearchAdd: **PredecessorList");
-  Free((void **)&ShortestPathList, "molecule::BreadthFirstSearchAdd: **ShortestPathList");
-  Free((void **)&ColorList, "molecule::BreadthFirstSearchAdd: **ColorList");
+  Free(&PredecessorList);
+  Free(&ShortestPathList);
+  Free(&ColorList);
   delete(AtomStack);
 };
@@ -4309,5 +4310,5 @@
   atom *Walker = NULL, *OtherAtom = NULL;
   bool status = true;
-  atom **ParentList = (atom **) Malloc(sizeof(atom *)*Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
+  atom **ParentList = Malloc<atom*>(Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
 
   *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
@@ -4348,5 +4349,5 @@
   }
 
-  Free((void **)&ParentList, "molecule::BuildInducedSubgraph: **ParentList");
+  Free(&ParentList);
   *out << Verbose(2) << "End of BuildInducedSubgraph." << endl;
   return status;
@@ -4391,5 +4392,5 @@
 {
   atom *Runner = NULL, *FatherOfRunner = NULL, *OtherFather = NULL;
-  atom **SonList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::StoreFragmentFromStack: **SonList");
+  atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
   molecule *Leaf = new molecule(elemente);
   bool LonelyFlag = false;
@@ -4461,5 +4462,5 @@
   Leaf->CreateListOfBondsPerAtom(out);
   //Leaflet->Leaf->ScanForPeriodicCorrection(out);
-  Free((void **)&SonList, "molecule::StoreFragmentFromStack: **SonList");
+  Free(&SonList);
 //  *out << Verbose(1) << "End of StoreFragmentFromKeyset." << endl;
   return Leaf;
@@ -4482,9 +4483,9 @@
 MoleculeListClass * molecule::CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, config *configuration)
 {
-  atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
-  int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
-  int *Labels = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
-  enum Shading *ColorVertexList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
-  enum Shading *ColorEdgeList = (enum Shading *) Malloc(sizeof(enum Shading)*BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList");
+  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
+  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
+  int *Labels = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
+  enum Shading *ColorVertexList = Malloc<enum Shading>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
+  enum Shading *ColorEdgeList = Malloc<enum Shading>(BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList");
   StackClass<atom *> *RootStack = new StackClass<atom *>(AtomCount);
   StackClass<atom *> *TouchedStack = new StackClass<atom *>((int)pow(4,Order)+2); // number of atoms reached from one with maximal 4 bonds plus Root itself
@@ -4616,8 +4617,8 @@
 
   // free memory and exit
-  Free((void **)&PredecessorList, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
-  Free((void **)&ShortestPathList, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
-  Free((void **)&Labels, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
-  Free((void **)&ColorVertexList, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
+  Free(&PredecessorList);
+  Free(&ShortestPathList);
+  Free(&Labels);
+  Free(&ColorVertexList);
   delete(RootStack);
   delete(TouchedStack);
@@ -4669,5 +4670,5 @@
   int Removal;
   int SpaceLeft;
-  int *TouchedList = (int *) Malloc(sizeof(int)*(SubOrder+1), "molecule::SPFragmentGenerator: *TouchedList");
+  int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList");
   bond *Binder = NULL;
   bond **BondsList = NULL;
@@ -4677,6 +4678,6 @@
 
   // Hier muessen von 1 bis NumberOfBondsPerAtom[Walker->nr] alle Kombinationen
-  // von Endstuecken (aus den Bonds) hinzugefï¿œï¿œgt werden und fï¿œï¿œr verbleibende ANOVAOrder
-  // rekursiv GraphCrawler in der nï¿œï¿œchsten Ebene aufgerufen werden
+  // von Endstuecken (aus den Bonds) hinzugefuegt werden und fuer verbleibende ANOVAOrder
+  // rekursiv GraphCrawler in der naechsten Ebene aufgerufen werden
 
   *out << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl;
@@ -4738,5 +4739,5 @@
           }
           // then allocate and fill the list
-          BondsList = (bond **) Malloc(sizeof(bond *)*SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
+          BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
           SubSetDimension = 0;
           Binder = FragmentSearch->BondsPerSPList[2*SP];
@@ -4750,5 +4751,5 @@
           *out << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
           SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
-          Free((void **)&BondsList, "molecule::SPFragmentGenerator: **BondsList");
+          Free(&BondsList);
         }
       } else {
@@ -4784,5 +4785,5 @@
     }
   }
-  Free((void **)&TouchedList, "molecule::SPFragmentGenerator: *TouchedList");
+  Free(&TouchedList);
   *out << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl;
 };
@@ -4962,10 +4963,10 @@
     *out << Verbose(0) << "Preparing subset for this root and calling generator." << endl;
     // prepare the subset and call the generator
-    BondsList = (bond **) Malloc(sizeof(bond *)*FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
+    BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
 
     SPFragmentGenerator(out, &FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
 
-    Free((void **)&BondsList, "molecule::PowerSetGenerator: **BondsList");
+    Free(&BondsList);
   } else {
     *out << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl;
@@ -5021,5 +5022,5 @@
   *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl;
 
-  ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
+  ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
   while (flag) {
     // remove bonds that are beyond bonddistance
@@ -5082,6 +5083,6 @@
   // free allocated space from ReturnFullMatrixforSymmetric()
   delete(AtomStack);
-  Free((void **)&ColorList, "molecule::ScanForPeriodicCorrection: *ColorList");
-  Free((void **)&matrix, "molecule::ScanForPeriodicCorrection: *matrix");
+  Free(&ColorList);
+  Free(&matrix);
   *out << Verbose(2) << "End of ScanForPeriodicCorrection." << endl;
 };
@@ -5093,5 +5094,5 @@
 double * molecule::ReturnFullMatrixforSymmetric(double *symm)
 {
-  double *matrix = (double *) Malloc(sizeof(double)*NDIM*NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
+  double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
   matrix[0] = symm[0];
   matrix[1] = symm[1];
@@ -5220,9 +5221,9 @@
   // 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 = (int *) Malloc(sizeof(int)*UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
-  FragmentLowerOrdersList = (Graph ***) Malloc(sizeof(Graph **)*UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
+  NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
+  FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
 
   // initialise the fragments structure
-  FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
+  FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
   FragmentSearch.FragmentCounter = 0;
   FragmentSearch.FragmentSet = new KeySet;
@@ -5259,6 +5260,6 @@
 
       // initialise Order-dependent entries of UniqueFragments structure
-      FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
-      FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
+      FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList");
+      FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
       for (int i=Order;i--;) {
         FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
@@ -5271,5 +5272,5 @@
       // allocate memory for all lower level orders in this 1D-array of ptrs
       NumLevels = 1 << (Order-1); // (int)pow(2,Order);
-      FragmentLowerOrdersList[RootNr] = (Graph **) Malloc(sizeof(Graph *)*NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
+      FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
       for (int i=0;i<NumLevels;i++)
         FragmentLowerOrdersList[RootNr][i] = NULL;
@@ -5338,10 +5339,10 @@
 
       // free Order-dependent entries of UniqueFragments structure for next loop cycle
-      Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");
+      Free(&FragmentSearch.BondsPerSPCount);
       for (int i=Order;i--;) {
         delete(FragmentSearch.BondsPerSPList[2*i]);
         delete(FragmentSearch.BondsPerSPList[2*i+1]);
       }
-      Free((void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");
+      Free(&FragmentSearch.BondsPerSPList);
     }
   }
@@ -5351,5 +5352,5 @@
 
   // cleanup FragmentSearch structure
-  Free((void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");
+  Free(&FragmentSearch.ShortestPathList);
   delete(FragmentSearch.FragmentSet);
 
@@ -5382,9 +5383,9 @@
       }
     }
-    Free((void **)&FragmentLowerOrdersList[RootNr], "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
+    Free(&FragmentLowerOrdersList[RootNr]);
     RootNr++;
   }
-  Free((void **)&FragmentLowerOrdersList, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
-  Free((void **)&NumMoleculesOfOrder, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
+  Free(&FragmentLowerOrdersList);
+  Free(&NumMoleculesOfOrder);
 
   *out << Verbose(0) << "End of FragmentBOSSANOVA." << endl;
@@ -5476,6 +5477,6 @@
   if (result) {
     *out << Verbose(5) << "Calculating distances" << endl;
-    Distances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
-    OtherDistances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
+    Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
+    OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
     Walker = start;
     while (Walker->next != end) {
@@ -5491,14 +5492,14 @@
     /// ... sort each list (using heapsort (o(N log N)) from GSL)
     *out << Verbose(5) << "Sorting distances" << endl;
-    PermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
-    OtherPermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
+    PermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
+    OtherPermMap = Malloc<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 = (int *) Malloc(sizeof(int)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
+    PermutationMap = Malloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     *out << Verbose(5) << "Combining Permutation Maps" << endl;
     for(int i=AtomCount;i--;)
       PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
 
-    /// ... and compare them step by step, whether the difference is individiually(!) below \a threshold for all
+    /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all
     *out << Verbose(4) << "Comparing distances" << endl;
     flag = 0;
@@ -5508,12 +5509,12 @@
         flag = 1;
     }
-    Free((void **)&PermMap, "molecule::IsEqualToWithinThreshold: *PermMap");
-    Free((void **)&OtherPermMap, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
-
-    /// free memory
-    Free((void **)&Distances, "molecule::IsEqualToWithinThreshold: Distances");
-    Free((void **)&OtherDistances, "molecule::IsEqualToWithinThreshold: OtherDistances");
+
+    // free memory
+    Free(&PermMap);
+    Free(&OtherPermMap);
+    Free(&Distances);
+    Free(&OtherDistances);
     if (flag) { // if not equal
-      Free((void **)&PermutationMap, "molecule::IsEqualToWithinThreshold: *PermutationMap");
+      Free(&PermutationMap);
       result = false;
     }
@@ -5541,5 +5542,5 @@
   atom *Walker = NULL, *OtherWalker = NULL;
   *out << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;
-  int *AtomicMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::GetAtomicMap: *AtomicMap");  //Calloc
+  int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap");
   for (int i=AtomCount;i--;)
     AtomicMap[i] = -1;
