Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/Makefile.am	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -2,5 +2,5 @@
 HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
 
-noinst_PROGRAMS =  VectorUnitTest
+noinst_PROGRAMS =  VectorUnitTest MemoryAllocatorUnitTest
 
 bin_PROGRAMS = molecuilder joiner analyzer
@@ -11,5 +11,5 @@
 analyzer_SOURCES = analyzer.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp helpers.hpp periodentafel.hpp parser.hpp datacreator.hpp 
 
-TESTS = VectorUnitTest
+TESTS = VectorUnitTest MemoryAllocatorUnitTest
 check_PROGRAMS = $(TESTS)
 VectorUnitTest_SOURCES = defs.hpp helpers.cpp helpers.hpp leastsquaremin.cpp leastsquaremin.hpp vectorunittest.cpp vectorunittest.hpp vector.cpp vector.hpp verbose.cpp verbose.hpp 
@@ -17,3 +17,8 @@
 VectorUnitTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl
 
+MemoryAllocatorUnitTest_SOURCES = defs.hpp helpers.cpp helpers.hpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp memoryallocator.hpp verbose.cpp verbose.hpp 
+MemoryAllocatorUnitTest_CXXFLAGS = $(CPPUNIT_CFLAGS)
+MemoryAllocatorUnitTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl
+
+
 EXTRA_DIST = ${molecuilder_DATA}
Index: src/analyzer.cpp
===================================================================
--- src/analyzer.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/analyzer.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -10,4 +10,5 @@
 #include "datacreator.hpp"
 #include "helpers.hpp"
+#include "memoryallocator.hpp"
 #include "parser.hpp"
 #include "periodentafel.hpp"
@@ -72,5 +73,5 @@
     return 1;
   } else {
-    dir = (char *) Malloc(sizeof(char)*(strlen(argv[2])+2), "main: *dir");
+    dir = Malloc<char>(strlen(argv[2]) + 2, "main: *dir");
     strcpy(dir, "/");
     strcat(dir, argv[2]);
@@ -555,5 +556,5 @@
   // ++++++++++++++++ exit ++++++++++++++++++++++++++++++++++
   delete(periode);
-  Free((void **)&dir, "main: *dir");
+  Free(&dir);
   cout << "done." << endl;
   return 0;
Index: src/atom.cpp
===================================================================
--- src/atom.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/atom.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -6,4 +6,5 @@
 
 #include "atom.hpp"
+#include "memoryallocator.hpp"
 
 /************************************* Functions for class atom *************************************/
@@ -61,5 +62,5 @@
 atom::~atom()
 {
-  Free((void **)&ComponentNr, "atom::~atom: *ComponentNr");
+  Free(&ComponentNr);
 };
 
Index: src/boundary.cpp
===================================================================
--- src/boundary.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/boundary.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -6,4 +6,5 @@
 
 #include "boundary.hpp"
+#include "memoryallocator.hpp"
 
 #include<gsl/gsl_poly.h>
Index: src/config.cpp
===================================================================
--- src/config.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/config.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -6,4 +6,5 @@
 
 #include "config.hpp"
+#include "memoryallocator.hpp"
 
 /******************************** Functions for class ConfigFileBuffer **********************/
@@ -86,5 +87,5 @@
     return;
   } else
-    buffer = (char **) Malloc(sizeof(char *)*NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
+    buffer = Malloc<char*>(NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
 
   // scan each line and put into buffer
@@ -92,5 +93,5 @@
   int i;
   do {
-    buffer[lines] = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
+    buffer[lines] = Malloc<char>(MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
     file->getline(buffer[lines], MAXSTRINGSIZE-1);
     i = strlen(buffer[lines]);
@@ -112,7 +113,7 @@
 {
   for(int i=0;i<NoLines;++i)
-    Free((void **)&buffer[i], "ConfigFileBuffer::~ConfigFileBuffer: *buffer[]");
-  Free((void **)&buffer, "ConfigFileBuffer::~ConfigFileBuffer: **buffer");
-  Free((void **)&LineMapping, "ConfigFileBuffer::~ConfigFileBuffer: *LineMapping");
+    Free(&buffer[i]);
+  Free(&buffer);
+  Free(&LineMapping);
 }
 
@@ -122,5 +123,5 @@
 void ConfigFileBuffer::InitMapping()
 {
-  LineMapping = (int *) Malloc(sizeof(int)*NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
+  LineMapping = Malloc<int>(NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
   for (int i=0;i<NoLines;i++)
     LineMapping[i] = i;
@@ -163,14 +164,14 @@
 config::config()
 {
-  mainname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname");
-  defaultpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: defaultpath");
-  pseudopotpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: pseudopotpath");
-  databasepath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: databasepath");
-  configpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: configpath");
-  configname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: configname");
-  ThermostatImplemented = (int *) Malloc((MaxThermostats)*(sizeof(int)), "config constructor: *ThermostatImplemented");
-  ThermostatNames = (char **) Malloc((MaxThermostats)*(sizeof(char *)), "config constructor: *ThermostatNames");
+  mainname = Malloc<char>(MAXSTRINGSIZE,"config constructor: mainname");
+  defaultpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: defaultpath");
+  pseudopotpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: pseudopotpath");
+  databasepath = Malloc<char>(MAXSTRINGSIZE,"config constructor: databasepath");
+  configpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: configpath");
+  configname = Malloc<char>(MAXSTRINGSIZE,"config constructor: configname");
+  ThermostatImplemented = Malloc<int>(MaxThermostats, "config constructor: *ThermostatImplemented");
+  ThermostatNames = Malloc<char*>(MaxThermostats, "config constructor: *ThermostatNames");
   for (int j=0;j<MaxThermostats;j++)
-    ThermostatNames[j] = (char *) MallocString(12*(sizeof(char)), "config constructor: ThermostatNames[]");
+    ThermostatNames[j] = Malloc<char>(12, "config constructor: ThermostatNames[]");
   Thermostat = 4;
   alpha = 0.;
@@ -263,14 +264,14 @@
 config::~config()
 {
-  Free((void **)&mainname, "config::~config: *mainname");
-  Free((void **)&defaultpath, "config::~config: *defaultpath");
-  Free((void **)&pseudopotpath, "config::~config: *pseudopotpath");
-  Free((void **)&databasepath, "config::~config: *databasepath");
-  Free((void **)&configpath, "config::~config: *configpath");
-  Free((void **)&configname, "config::~config: *configname");
-  Free((void **)&ThermostatImplemented, "config::~config: *ThermostatImplemented");
+  Free(&mainname);
+  Free(&defaultpath);
+  Free(&pseudopotpath);
+  Free(&databasepath);
+  Free(&configpath);
+  Free(&configname);
+  Free(&ThermostatImplemented);
   for (int j=0;j<MaxThermostats;j++)
-    Free((void **)&ThermostatNames[j], "config::~config: *ThermostatNames[]");
-  Free((void **)&ThermostatNames, "config::~config: **ThermostatNames");
+    Free(&ThermostatNames[j]);
+  Free(&ThermostatNames);
 };
 
@@ -280,5 +281,5 @@
 void config::InitThermostats(class ConfigFileBuffer *fb)
 {
-  char *thermo = MallocString(12, "IonsInitRead: thermo");
+  char *thermo = Malloc<char>(12, "IonsInitRead: thermo");
   int verbose = 0;
 
@@ -347,5 +348,5 @@
     Thermostat = None;
   }
-  Free((void **)&thermo, "InitThermostats: thermo");
+  Free(&thermo);
 };
 
@@ -1533,5 +1534,5 @@
   long file_position = file->tellg(); // mark current position
   char *dummy1, *dummy, *free_dummy;    // pointers in the line that is read in per step
-  dummy1 = free_dummy = (char *) Malloc(256 * sizeof(char), "config::ParseForParameter: *free_dummy");
+  dummy1 = free_dummy = Malloc<char>(256, "config::ParseForParameter: *free_dummy");
 
   //fprintf(stderr,"Parsing for %s\n",name);
@@ -1548,5 +1549,5 @@
       if (file->eof()) {
         if ((critical) && (found == 0)) {
-          Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
+          Free(&free_dummy);
           //Error(InitReading, name);
           fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
@@ -1556,5 +1557,5 @@
           file->clear();
           file->seekg(file_position, ios::beg);  // rewind to start position
-          Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
+          Free(&free_dummy);
           return 0;
         }
@@ -1608,5 +1609,5 @@
               if (file->eof()) {
                 if ((critical) && (found == 0)) {
-                  Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
+                  Free(&free_dummy);
                   //Error(InitReading, name);
                   fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
@@ -1616,5 +1617,5 @@
                   file->clear();
                   file->seekg(file_position, ios::beg);  // rewind to start position
-                  Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
+                  Free(&free_dummy);
                   return 0;
                 }
@@ -1657,5 +1658,5 @@
                   if (critical) {
                     if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
-                    Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
+                    Free(&free_dummy);
                     //return 0;
                     exit(255);
@@ -1665,5 +1666,5 @@
                     file->clear();
                     file->seekg(file_position, ios::beg);  // rewind to start position
-                    Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
+                    Free(&free_dummy);
                     return 0;
                   }
@@ -1678,5 +1679,5 @@
                   file->seekg(file_position, ios::beg);  // rewind to start position
                 }
-                Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
+                Free(&free_dummy);
                 return 0;
               }
@@ -1732,6 +1733,7 @@
     }
   }
-  if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
-  Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
+  if ((type >= row_int) && (verbose))
+    fprintf(stderr,"\n");
+  Free(&free_dummy);
   if (!sequential) {
     file->clear();
@@ -1811,5 +1813,5 @@
         dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
         //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
-        //Free((void **)&free_dummy);
+        //Free(&free_dummy);
         //Error(FileOpenParams, NULL);
       } else {
Index: src/defs.hpp
===================================================================
--- src/defs.hpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/defs.hpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -7,6 +7,4 @@
 #ifndef DEFS_HPP_
 #define DEFS_HPP_
-
-using namespace std;
 
 #define MYEPSILON 1e-13   //!< machine epsilon precision
Index: src/helpers.cpp
===================================================================
--- src/helpers.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/helpers.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -34,83 +34,4 @@
 void debug_in(const char *output, const char *file, const int line) {}  // print nothing
 #endif
-
-/** Wrapper for allocating'ing a memory range with *output if it fails.
- * \param size number of chars to alloc for \a *buffer
- * \param *output message if malloc fails
- * \return pointer to memory range
- */
-void * Malloc(size_t size, const char* output)
-{
-  void *buffer = NULL;
-  buffer = (void *)malloc(size); // alloc
-  if (buffer == NULL)
-    cout << Verbose(0) << "Malloc failed - pointer is NULL: " << output << endl;
-  return(buffer);
-};
-
-/** Wrapper for allocating'ing a memory range with *output if it fails.
- * \param size number of chars to alloc for \a *buffer
- * \param *output message if malloc fails
- * \return pointer to memory range
- */
-void * Calloc(size_t size, const char* output)
-{
-  void *buffer = NULL;
-  buffer = (void *)calloc(size, (size_t)0); // alloc
-  if (buffer == NULL)
-    cout << Verbose(0) << "Calloc failed - pointer is NULL: " << output << endl;
-  return(buffer);
-};
-
-/** Wrapper for reallocating'ing a memory range with *output if it fails.
- * \param *OldPointer pointer to old memory range
- * \param size number of chars to alloc for \a *buffer
- * \param *output message if malloc fails
- * \return pointer to memory range
- */
-void * ReAlloc(void * OldPointer, size_t size, const char* output)
-{
-  void *buffer = NULL;
-  if (OldPointer == NULL)
-    //cout << Verbose(0) << "ReAlloc impossible - old is NULL: " << output << endl;
-    buffer = (void *)malloc(size); // malloc
-  else
-    buffer = (void *)realloc(OldPointer, size); // realloc
-  if (buffer == NULL)
-    cout << Verbose(0) << "ReAlloc failed - new is NULL: " << output << endl;
-  return(buffer);
-};
-
-/** Wrapper for free'ing an allocated memory range with *output if it fails.
- * \param *buffer pointer to buffer to be free'd
- * \param *output message if free fails
- */
-void Free(void ** buffer, const char* output)
-{
-  if (*buffer == NULL) {
-    //cout << Verbose(5) << "Free not necesary: " << output << endl;
-  } else {
-    free(*buffer);
-    *buffer = NULL;
-  }
-};
-
-/** Malloc string array and set its length to the allocated length.
- * \param *output message if malloc fails
- * \param size number of chars to alloc for \a *buffer
- * \return pointer to string array
- */
-char* MallocString(size_t size, const char* output)
-{
-  size_t i;
-  char *buffer;
-  buffer = (char *)malloc(sizeof(char) * (size+1)); // alloc
-  if (buffer == NULL)
-    cout << Verbose(0) << output << endl;
-  for (i=size;i--;)  // reset
-    buffer[i] = i % 2 == 0 ? 'p': 'c';
-  buffer[size] = '\0'; // and set length marker on its end
-  return(buffer);
-}
 
 /** modulo operator for doubles.
@@ -170,5 +91,5 @@
   }
   // allocate string
-  returnstring = (char *) Malloc(sizeof(char)*(order+2), "FixedDigitNumber: *returnstring");
+  returnstring = Malloc<char>(order + 2, "FixedDigitNumber: *returnstring");
   // terminate  and fill string array from end backward
   returnstring[order] = '\0';
@@ -196,3 +117,26 @@
 };
 
+/**
+ * Allocates a memory range using malloc().
+ * Prints the provided error message in case of a failure.
+ *
+ * \param number of memory slices of type X to allocate
+ * \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 <> char* Malloc<char>(size_t size, const char* output)
+{
+  char* buffer = NULL;
+  buffer = (char*) malloc(sizeof(char) * (size + 1));
+  for (size_t i = size; i--;)
+    buffer[i] = (i % 2 == 0) ? 'p': 'c';
+  buffer[size] = '\0';
 
+  if (buffer == NULL)
+    cout << Verbose(0) << "Malloc for datatype " << typeid(char).name()
+      << " failed - pointer is NULL: " << output << endl;
+
+  return buffer;
+};
+
+
Index: src/helpers.hpp
===================================================================
--- src/helpers.hpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/helpers.hpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -23,4 +23,5 @@
 #include "defs.hpp"
 #include "verbose.hpp"
+#include "memoryallocator.hpp"
 
 /********************************************** helpful functions *********************************/
@@ -50,9 +51,9 @@
 void flip(double *x, double *y);
 int pot(int base, int n);
-void * Malloc(size_t size, const char* output);
-void * Calloc(size_t size, const char* output);
-void * ReAlloc(void * OldPointer, size_t size, const char* output);
-char* MallocString(size_t size, const char* output);
-void Free(void ** buffer, const char* output);
+//void * Malloc(size_t size, const char* output);
+//void * Calloc(size_t size, const char* output);
+//void * ReAlloc(void * OldPointer, size_t size, const char* output);
+//char* MallocString(size_t size, const char* output);
+//void Free(void ** buffer, const char* output);
 char *FixedDigitNumber(const int FragmentNumber, const int digits);
 bool IsValidNumber( const char *string);
@@ -93,5 +94,5 @@
 
   // allocat and fill
-  LookupTable = (T **) Malloc(sizeof(T *)*count, "CreateFatherLookupTable - **LookupTable");
+  LookupTable = Malloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
   if (LookupTable == NULL) {
     cerr << "LookupTable memory allocation failed!" << endl;
@@ -273,3 +274,4 @@
 
 
+
 #endif /*HELPERS_HPP_*/
Index: src/joiner.cpp
===================================================================
--- src/joiner.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/joiner.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -10,4 +10,5 @@
 #include "datacreator.hpp"
 #include "helpers.hpp"
+#include "memoryallocator.hpp"
 #include "parser.hpp"
 #include "periodentafel.hpp"
@@ -55,5 +56,5 @@
     return 1;
   } else {
-    dir = (char *) Malloc(sizeof(char)*(strlen(argv[2])+2), "main: *dir");
+    dir = Malloc<char>(strlen(argv[2]) + 2, "main: *dir");
     strcpy(dir, "/");
     strcat(dir, argv[2]);
@@ -240,5 +241,5 @@
   // exit
   delete(periode);
-  Free((void **)&dir, "main: *dir");
+  Free(&dir);
   cout << "done." << endl;
   return 0;
Index: src/memoryallocator.hpp
===================================================================
--- src/memoryallocator.hpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
+++ src/memoryallocator.hpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -0,0 +1,109 @@
+/** \file memoryallocator.hpp
+ *
+ * This file provides wrappers for C++'s memory allocation functions.
+ */
+
+#ifndef MEMORYALLOCATOR_HPP_
+#define MEMORYALLOCATOR_HPP_
+
+using namespace std;
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <sstream>
+#include <math.h>
+#include <string>
+#include <typeinfo>
+
+#include "defs.hpp"
+#include "verbose.hpp"
+
+/******************* wrappers for memory allocation functions ***********************/
+
+/**
+ * Allocates a memory range using malloc().
+ * Prints the provided error message in case of a failure.
+ *
+ * \param number of memory slices of type X to allocate
+ * \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* Malloc(size_t size, const char* output)
+{
+  X* buffer = NULL;
+  buffer = (X*) malloc(sizeof(X) * size);
+
+  if (buffer == NULL)
+    cout << Verbose(0) << "Malloc for datatype " << typeid(X).name()
+      << " failed - pointer is NULL: " << output << endl;
+
+  return buffer;
+};
+
+/** \see helpers.cpp for Malloc<char> */
+template <> char* Malloc<char>(size_t size, const char* output);
+
+/**
+ * Allocates a memory range using calloc().
+ * Prints the provided error message in case of a failure.
+ *
+ * \param number of memory slices of type X to allocate
+ * \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);
+  if (buffer == NULL)
+    cout << Verbose(0) << "Calloc for datatype " << typeid(X).name()
+      << " failed - pointer is NULL: " << output << endl;
+
+  return buffer;
+};
+
+/**
+ * Reallocates a memory range using realloc(). If the provided pointer to the old
+ * memory range is NULL, malloc() is called instead.
+ * Prints the provided error message in case of a failure (of either malloc() or realloc()).
+ *
+ * \param pointer to the old memory range
+ * \param number of memory slices of type X to allocate
+ * \param failure message which is printed if the allocation fails
+ * \return pointer to the reallocated memory range, will be NULL if a failure occurred
+ */
+template <typename X> X* ReAlloc(X* OldPointer, size_t size, const char* output)
+{
+  X* buffer = NULL;
+  if (OldPointer == NULL)
+    buffer = (X*) malloc(sizeof(X) * size);
+  else
+    buffer = (X*) realloc(OldPointer, sizeof(X) * size);
+  if (buffer == NULL)
+    cout << Verbose(0) << "ReAlloc for datatype " << typeid(X).name()
+      << " failed - new is NULL: " << output << endl;
+
+  return buffer;
+};
+
+/**
+ * Frees allocated memory range using free().
+ *
+ * \param pointer to the allocated memory range to free; may be NULL, this function is a no-op then
+ */
+template <typename X> void Free(X** buffer)
+{
+  if ((buffer == NULL) || (*buffer == NULL))
+    return;
+
+  free(*buffer);
+  *buffer = NULL;
+};
+
+#endif /*MEMORYALLOCATOR_HPP_*/
Index: src/memoryallocatorunittest.cpp
===================================================================
--- src/memoryallocatorunittest.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
+++ src/memoryallocatorunittest.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -0,0 +1,120 @@
+/*
+ * memoryallocatorunittest.cpp
+ */
+
+
+using namespace std;
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include "memoryallocator.hpp"
+#include "memoryallocatorunittest.hpp"
+#include "helpers.hpp"
+#include "defs.hpp"
+
+/********************************************** Test classes **************************************/
+
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( MemoryAllocatorTest );
+
+
+void MemoryAllocatorTest::setUp()
+{
+};
+
+
+void MemoryAllocatorTest::tearDown()
+{
+};
+
+/**
+ * UnitTest for Malloc()
+ */
+void MemoryAllocatorTest::MallocTest()
+{
+  int* buffer1 = NULL;
+  buffer1 = Malloc<int>(1, "");
+  Free(&buffer1);
+
+  long* buffer2 = NULL;
+  buffer2 = Malloc<long>(1, "");
+  Free(&buffer2);
+
+  char* buffer3 = NULL;
+  buffer3 = Malloc<char>(4, "");
+  cout << buffer3 << endl;
+  Free(&buffer3);
+
+  char** buffer4 = NULL;
+  buffer4 = Malloc<char*>(1, "");
+  Free(&buffer4);
+};
+
+/**
+ * UnitTest for Calloc()
+ */
+void MemoryAllocatorTest::CallocTest()
+{
+  int* buffer1 = NULL;
+  buffer1 = Calloc<int>(1, "");
+  Free(&buffer1);
+
+  long* buffer2 = NULL;
+  buffer2 = Calloc<long>(1, "");
+  Free(&buffer2);
+
+  char* buffer3 = NULL;
+  buffer3 = Calloc<char>(1, "");
+  Free(&buffer3);
+};
+
+/**
+ * UnitTest for ReAlloc()
+ */
+void MemoryAllocatorTest::ReAllocTest()
+{
+  int* buffer1 = NULL;
+  buffer1 = Malloc<int>(1, "");
+  buffer1 = ReAlloc<int>(buffer1, 2, "");
+  Free(&buffer1);
+
+  int* buffer2 = NULL;
+  buffer2 = ReAlloc<int>(buffer2, 2, "");
+  Free(&buffer2);
+};
+
+/**
+ * UnitTest for Free()
+ */
+void MemoryAllocatorTest::FreeTest()
+{
+  char** buffer1 = NULL;
+  Free(buffer1);
+
+  int** buffer2 = NULL;
+  Free(buffer2);
+};
+
+
+/********************************************** Main routine **************************************/
+
+int main(int argc, char **argv)
+{
+  // Get the top level suite from the registry
+  CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
+
+  // Adds the test to the list of test to run
+  CppUnit::TextUi::TestRunner runner;
+  runner.addTest( suite );
+
+  // Change the default outputter to a compiler error format outputter
+  runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
+                                                       std::cerr ) );
+  // Run the tests.
+  bool wasSucessful = runner.run();
+
+  // Return error code 1 if the one of test failed.
+  return wasSucessful ? 0 : 1;
+};
Index: src/memoryallocatorunittest.hpp
===================================================================
--- src/memoryallocatorunittest.hpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
+++ src/memoryallocatorunittest.hpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -0,0 +1,32 @@
+/*
+ * memoryallocatorunittest.hpp
+ */
+
+#ifndef MEMORYALLOCATORTEST_HPP_
+#define MEMORYALLOCATORTEST_HPP_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+
+/********************************************** Test classes **************************************/
+
+class MemoryAllocatorTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( MemoryAllocatorTest) ;
+    CPPUNIT_TEST ( MallocTest );
+    CPPUNIT_TEST ( CallocTest );
+    CPPUNIT_TEST ( ReAllocTest );
+    CPPUNIT_TEST ( FreeTest );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+    void setUp();
+    void tearDown();
+
+    void MallocTest();
+    void CallocTest();
+    void ReAllocTest();
+    void FreeTest();
+};
+
+#endif /* MEMORYALLOCATORTEST_HPP_ */
Index: src/moleculelist.cpp
===================================================================
--- src/moleculelist.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/moleculelist.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -7,4 +7,5 @@
 #include "config.hpp"
 #include "molecules.hpp"
+#include "memoryallocator.hpp"
 
 /*********************************** Functions for class MoleculeListClass *************************/
@@ -375,9 +376,9 @@
 
   // 0b. allocate memory for constants
-  FitConstant = (double ***) Malloc(sizeof(double **) * 3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
+  FitConstant = Malloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
   for (int k = 0; k < 3; k++) {
-    FitConstant[k] = (double **) Malloc(sizeof(double *) * a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
+    FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     for (int i = a; i--;) {
-      FitConstant[k][i] = (double *) Malloc(sizeof(double) * b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
+      FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
     }
   }
@@ -424,7 +425,7 @@
 
   // 0d. allocate final correction matrix
-  correction = (double **) Malloc(sizeof(double *) * a, "MoleculeListClass::AddHydrogenCorrection: **correction");
+  correction = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");
   for (int i = a; i--;)
-    correction[i] = (double *) Malloc(sizeof(double) * b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
+    correction[i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
 
   // 1a. go through every molecule in the list
@@ -500,9 +501,9 @@
   output.close();
   // 6. free memory of parsed matrices
-  FitConstant = (double ***) Malloc(sizeof(double **) * a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
+  FitConstant = Malloc<double**>(a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
   for (int k = 0; k < 3; k++) {
-    FitConstant[k] = (double **) Malloc(sizeof(double *) * a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
+    FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     for (int i = a; i--;) {
-      FitConstant[k][i] = (double *) Malloc(sizeof(double) * b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
+      FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
     }
   }
@@ -665,5 +666,5 @@
     //outputFragment.clear();
     delete (FragmentNumber);
-    //Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber");
+    //Free(&FragmentNumber);
   }
   cout << " done." << endl;
@@ -808,7 +809,7 @@
   if ((FreeList) && (ListOfLocalAtoms != NULL)) {
     // free the index lookup list
-    Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::FillBondStructureFromReference - **ListOfLocalAtoms[]");
+    Free(&ListOfLocalAtoms[FragmentCounter]);
     if (FragmentCounter == 0) // first fragments frees the initial pointer to list
-      Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
+      Free(&ListOfLocalAtoms);
   }
   FragmentCounter--;
@@ -873,5 +874,5 @@
   if (ListOfLocalAtoms == NULL) { // allocated initial pointer
     // allocate and set each field to NULL
-    ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **) * Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
+    ListOfLocalAtoms = Malloc<atom**>(Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
     if (ListOfLocalAtoms != NULL) {
       for (int i = Counter; i--;)
@@ -917,5 +918,5 @@
   if (FragmentList == NULL) {
     KeySetCounter = Count();
-    FragmentList = (Graph **) Malloc(sizeof(Graph *) * KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
+    FragmentList = Malloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
     for (int i = KeySetCounter; i--;)
       FragmentList[i] = NULL;
@@ -953,7 +954,7 @@
   if ((FreeList) && (ListOfLocalAtoms != NULL)) {
     // free the index lookup list
-    Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::AssignKeySetsToFragment - **ListOfLocalAtoms[]");
+    Free(&ListOfLocalAtoms[FragmentCounter]);
     if (FragmentCounter == 0) // first fragments frees the initial pointer to list
-      Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::AssignKeySetsToFragment - ***ListOfLocalAtoms");
+      Free(&ListOfLocalAtoms);
   }
   *out << Verbose(1) << "End of AssignKeySetsToFragment." << endl;
Index: src/molecules.cpp
===================================================================
--- src/molecules.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/molecules.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -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;
Index: src/parser.cpp
===================================================================
--- src/parser.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/parser.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -8,4 +8,5 @@
 
 #include "helpers.hpp"
+#include "memoryallocator.hpp"
 #include "parser.hpp"
 
@@ -56,8 +57,8 @@
 MatrixContainer::MatrixContainer() {
   Indices = NULL;
-  Header = (char **) Malloc(sizeof(char)*1, "MatrixContainer::MatrixContainer: **Header");
-  Matrix = (double ***) Malloc(sizeof(double **)*(1), "MatrixContainer::MatrixContainer: ***Matrix"); // one more each for the total molecule
-  RowCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *RowCounter");
-  ColumnCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *ColumnCounter");
+  Header = Malloc<char*>(1, "MatrixContainer::MatrixContainer: **Header");
+  Matrix = Malloc<double**>(1, "MatrixContainer::MatrixContainer: ***Matrix"); // one more each for the total molecule
+  RowCounter = Malloc<int>(1, "MatrixContainer::MatrixContainer: *RowCounter");
+  ColumnCounter = Malloc<int>(1, "MatrixContainer::MatrixContainer: *ColumnCounter");
   Header[0] = NULL;
   Matrix[0] = NULL;
@@ -74,27 +75,27 @@
       if ((ColumnCounter != NULL) && (RowCounter != NULL)) {
           for(int j=RowCounter[i]+1;j--;)
-            Free((void **)&Matrix[i][j], "MatrixContainer::~MatrixContainer: *Matrix[][]");
-        Free((void **)&Matrix[i], "MatrixContainer::~MatrixContainer: **Matrix[]");
+            Free(&Matrix[i][j]);
+        Free(&Matrix[i]);
       }
     }
     if ((ColumnCounter != NULL) && (RowCounter != NULL) && (Matrix[MatrixCounter] != NULL))
       for(int j=RowCounter[MatrixCounter]+1;j--;)
-        Free((void **)&Matrix[MatrixCounter][j], "MatrixContainer::~MatrixContainer: *Matrix[MatrixCounter][]");
+        Free(&Matrix[MatrixCounter][j]);
     if (MatrixCounter != 0)
-      Free((void **)&Matrix[MatrixCounter], "MatrixContainer::~MatrixContainer: **Matrix[MatrixCounter]");
-    Free((void **)&Matrix, "MatrixContainer::~MatrixContainer: ***Matrix");
+      Free(&Matrix[MatrixCounter]);
+    Free(&Matrix);
   }
   if (Indices != NULL)
     for(int i=MatrixCounter+1;i--;) {
-      Free((void **)&Indices[i], "MatrixContainer::~MatrixContainer: *Indices[]");
-    }
-  Free((void **)&Indices, "MatrixContainer::~MatrixContainer: **Indices"); 
+      Free(&Indices[i]);
+    }
+  Free(&Indices);
   
   if (Header != NULL)
     for(int i=MatrixCounter+1;i--;)
-      Free((void **)&Header[i], "MatrixContainer::~MatrixContainer: *Header[]");
-  Free((void **)&Header, "MatrixContainer::~MatrixContainer: **Header");
-  Free((void **)&RowCounter, "MatrixContainer::~MatrixContainer: *RowCounter");
-  Free((void **)&ColumnCounter, "MatrixContainer::~MatrixContainer: *RowCounter");
+      Free(&Header[i]);
+  Free(&Header);
+  Free(&RowCounter);
+  Free(&ColumnCounter);
 };
 
@@ -109,7 +110,7 @@
   if (Matrix == NULL) {
     cout << " with trivial mapping." << endl;
-    Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "MatrixContainer::InitialiseIndices: **Indices");
+    Indices = Malloc<int*>(MatrixCounter + 1, "MatrixContainer::InitialiseIndices: **Indices");
     for(int i=MatrixCounter+1;i--;) {
-      Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
+      Indices[i] = Malloc<int>(RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
       for(int j=RowCounter[i];j--;)
         Indices[i][j] = j;
@@ -119,9 +120,9 @@
     if (MatrixCounter != Matrix->MatrixCounter)
       return false;
-    Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "MatrixContainer::InitialiseIndices: **Indices");
+    Indices = Malloc<int*>(MatrixCounter + 1, "MatrixContainer::InitialiseIndices: **Indices");
     for(int i=MatrixCounter+1;i--;) {
       if (RowCounter[i] != Matrix->RowCounter[i])
         return false;
-      Indices[i] = (int *) Malloc(sizeof(int)*Matrix->RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
+      Indices[i] = Malloc<int>(Matrix->RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
       for(int j=Matrix->RowCounter[i];j--;) {
         Indices[i][j] = Matrix->Indices[i][j];
@@ -162,5 +163,5 @@
 
   // parse header
-  Header[MatrixNr] = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::ParseMatrix: *Header[]");
+  Header[MatrixNr] = Malloc<char>(1024, "MatrixContainer::ParseMatrix: *Header[]");
   for (int m=skiplines+1;m--;)
     input.getline(Header[MatrixNr], 1023);
@@ -197,5 +198,5 @@
   // allocate matrix if it's not zero dimension in one direction
   if ((ColumnCounter[MatrixNr] > 0) && (RowCounter[MatrixNr] > -1)) {
-    Matrix[MatrixNr] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixNr]+1), "MatrixContainer::ParseMatrix: **Matrix[]");
+    Matrix[MatrixNr] = Malloc<double*>(RowCounter[MatrixNr] + 1, "MatrixContainer::ParseMatrix: **Matrix[]");
   
     // parse in each entry for this matrix
@@ -209,5 +210,5 @@
     strncpy(Header[MatrixNr], line.str().c_str(), 1023);  
     for(int j=0;j<RowCounter[MatrixNr];j++) {
-      Matrix[MatrixNr][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[][]");
+      Matrix[MatrixNr][j] = Malloc<double>(ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[][]");
       input.getline(filename, 1023);
       stringstream lines(filename);
@@ -220,5 +221,5 @@
       }
       //cout << endl;
-      Matrix[MatrixNr][ RowCounter[MatrixNr] ] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[RowCounter[MatrixNr]][]");
+      Matrix[MatrixNr][ RowCounter[MatrixNr] ] = Malloc<double>(ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[RowCounter[MatrixNr]][]");
       for(int j=ColumnCounter[MatrixNr];j--;)
         Matrix[MatrixNr][ RowCounter[MatrixNr] ][j] = 0.;
@@ -274,8 +275,8 @@
 
   cout << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl;
-  Header = (char **) ReAlloc(Header, sizeof(char *)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: **Header"); // one more each for the total molecule
-  Matrix = (double ***) ReAlloc(Matrix, sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
-  RowCounter = (int *) ReAlloc(RowCounter, sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter");
-  ColumnCounter = (int *) ReAlloc(ColumnCounter, sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *ColumnCounter");
+  Header = ReAlloc<char*>(Header, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: **Header"); // one more each for the total molecule
+  Matrix = ReAlloc<double**>(Matrix, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
+  RowCounter = ReAlloc<int>(RowCounter, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: *RowCounter");
+  ColumnCounter = ReAlloc<int>(ColumnCounter, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: *ColumnCounter");
   for(int i=MatrixCounter+1;i--;) {
     Matrix[i] = NULL;
@@ -291,5 +292,5 @@
     if (!ParseMatrix(file.str().c_str(), skiplines, skipcolumns, i))
       return false;
-    Free((void **)&FragmentNumber, "MatrixContainer::ParseFragmentMatrix: *FragmentNumber");
+    Free(&FragmentNumber);
   }
   return true;
@@ -306,16 +307,16 @@
 {
   MatrixCounter = MCounter;
-  Header = (char **) Malloc(sizeof(char *)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: *Header");
-  Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: ***Matrix"); // one more each for the total molecule
-  RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: *RowCounter");
-  ColumnCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: *ColumnCounter");
+  Header = Malloc<char*>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: *Header");
+  Matrix = Malloc<double**>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: ***Matrix"); // one more each for the total molecule
+  RowCounter = Malloc<int>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: *RowCounter");
+  ColumnCounter = Malloc<int>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: *ColumnCounter");
   for(int i=MatrixCounter+1;i--;) {
-    Header[i] = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::AllocateMatrix: *Header[i]");
+    Header[i] = Malloc<char>(1024, "MatrixContainer::AllocateMatrix: *Header[i]");
     strncpy(Header[i], GivenHeader[i], 1023);
     RowCounter[i] = RCounter[i];
     ColumnCounter[i] = CCounter[i];
-    Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::AllocateMatrix: **Matrix[]");  
+    Matrix[i] = Malloc<double*>(RowCounter[i] + 1, "MatrixContainer::AllocateMatrix: **Matrix[]");
     for(int j=RowCounter[i]+1;j--;) {
-      Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter[i], "MatrixContainer::AllocateMatrix: *Matrix[][]");
+      Matrix[i][j] = Malloc<double>(ColumnCounter[i], "MatrixContainer::AllocateMatrix: *Matrix[][]");
       for(int k=ColumnCounter[i];k--;)
         Matrix[i][j][k] = 0.;
@@ -466,5 +467,5 @@
     FragmentNumber = FixedDigitNumber(MatrixCounter, i);
     line << name << FRAGMENTPREFIX << FragmentNumber << "/" << prefix;
-    Free((void **)&FragmentNumber, "*FragmentNumber");
+    Free(&FragmentNumber);
     output.open(line.str().c_str(), ios::out);
     if (output == NULL) {
@@ -520,7 +521,7 @@
 {
   cout << "Parsing energy indices." << endl;
-  Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "EnergyMatrix::ParseIndices: **Indices");
+  Indices = Malloc<int*>(MatrixCounter + 1, "EnergyMatrix::ParseIndices: **Indices");
   for(int i=MatrixCounter+1;i--;) {
-    Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "EnergyMatrix::ParseIndices: *Indices[]");
+    Indices[i] = Malloc<int>(RowCounter[i], "EnergyMatrix::ParseIndices: *Indices[]");
     for(int j=RowCounter[i];j--;)
       Indices[i][j] = j;
@@ -579,7 +580,7 @@
     // allocate last plus one matrix
     cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
-    Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
+    Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     for(int j=0;j<=RowCounter[MatrixCounter];j++)
-      Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
+      Matrix[MatrixCounter][j] = Malloc<double>(ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     
     // try independently to parse global energysuffix file if present
@@ -606,5 +607,5 @@
 
   cout << "Parsing force indices for " << MatrixCounter << " matrices." << endl;
-  Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "ForceMatrix::ParseIndices: **Indices");
+  Indices = Malloc<int*>(MatrixCounter + 1, "ForceMatrix::ParseIndices: **Indices");
   line << name << FRAGMENTPREFIX << FORCESFILE;
   input.open(line.str().c_str(), ios::in);
@@ -619,8 +620,8 @@
     line.str(filename);
     // parse the values
-    Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "ForceMatrix::ParseIndices: *Indices[]");
+    Indices[i] = Malloc<int>(RowCounter[i], "ForceMatrix::ParseIndices: *Indices[]");
     FragmentNumber = FixedDigitNumber(MatrixCounter, i);
     //cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
-    Free((void **)&FragmentNumber, "ForceMatrix::ParseIndices: *FragmentNumber");
+    Free(&FragmentNumber);
     for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
       line >> Indices[i][j];
@@ -629,5 +630,5 @@
     //cout << endl;
   }
-  Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "ForceMatrix::ParseIndices: *Indices[]");
+  Indices[MatrixCounter] = Malloc<int>(RowCounter[MatrixCounter], "ForceMatrix::ParseIndices: *Indices[]");
   for(int j=RowCounter[MatrixCounter];j--;) {
     Indices[MatrixCounter][j] = j;
@@ -714,7 +715,7 @@
     // allocate last plus one matrix
     cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
-    Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
+    Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     for(int j=0;j<=RowCounter[MatrixCounter];j++)
-      Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
+      Matrix[MatrixCounter][j] = Malloc<double>(ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
 
     // try independently to parse global forcesuffix file if present
@@ -743,5 +744,5 @@
   
   cout << "Parsing hessian indices for " << MatrixCounter << " matrices." << endl;
-  Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "HessianMatrix::ParseIndices: **Indices");
+  Indices = Malloc<int*>(MatrixCounter + 1, "HessianMatrix::ParseIndices: **Indices");
   line << name << FRAGMENTPREFIX << FORCESFILE;
   input.open(line.str().c_str(), ios::in);
@@ -756,8 +757,8 @@
     line.str(filename);
     // parse the values
-    Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "HessianMatrix::ParseIndices: *Indices[]");
+    Indices[i] = Malloc<int>(RowCounter[i], "HessianMatrix::ParseIndices: *Indices[]");
     FragmentNumber = FixedDigitNumber(MatrixCounter, i);
     //cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
-    Free((void **)&FragmentNumber, "HessianMatrix::ParseIndices: *FragmentNumber");
+    Free(&FragmentNumber);
     for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
       line >> Indices[i][j];
@@ -766,5 +767,5 @@
     //cout << endl;
   }
-  Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "HessianMatrix::ParseIndices: *Indices[]");
+  Indices[MatrixCounter] = Malloc<int>(RowCounter[MatrixCounter], "HessianMatrix::ParseIndices: *Indices[]");
   for(int j=RowCounter[MatrixCounter];j--;) {
     Indices[MatrixCounter][j] = j;
@@ -938,7 +939,7 @@
     // allocate last plus one matrix
     cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
-    Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
+    Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     for(int j=0;j<=RowCounter[MatrixCounter];j++)
-      Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
+      Matrix[MatrixCounter][j] = Malloc<double>(ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
 
     // try independently to parse global forcesuffix file if present
@@ -970,11 +971,11 @@
 KeySetsContainer::~KeySetsContainer() {
   for(int i=FragmentCounter;i--;)
-    Free((void **)&KeySets[i], "KeySetsContainer::~KeySetsContainer: *KeySets[]");
+    Free(&KeySets[i]);
   for(int i=Order;i--;)
-    Free((void **)&OrderSet[i], "KeySetsContainer::~KeySetsContainer: *OrderSet[]");
-  Free((void **)&KeySets, "KeySetsContainer::~KeySetsContainer: **KeySets");
-  Free((void **)&OrderSet, "KeySetsContainer::~KeySetsContainer: **OrderSet");
-  Free((void **)&AtomCounter, "KeySetsContainer::~KeySetsContainer: *AtomCounter");
-  Free((void **)&FragmentsPerOrder, "KeySetsContainer::~KeySetsContainer: *FragmentsPerOrder");
+    Free(&OrderSet[i]);
+  Free(&KeySets);
+  Free(&OrderSet);
+  Free(&AtomCounter);
+  Free(&FragmentsPerOrder);
 };
 
@@ -993,5 +994,5 @@
   FragmentCounter = FCounter;
   cout << "Parsing key sets." << endl;
-  KeySets = (int **) Malloc(sizeof(int *)*FragmentCounter, "KeySetsContainer::ParseKeySets: **KeySets");
+  KeySets = Malloc<int*>(FragmentCounter, "KeySetsContainer::ParseKeySets: **KeySets");
   for(int i=FragmentCounter;i--;)
     KeySets[i] = NULL;
@@ -1003,15 +1004,15 @@
   }
 
-  AtomCounter = (int *) Malloc(sizeof(int)*FragmentCounter, "KeySetsContainer::ParseKeySets: *RowCounter");
+  AtomCounter = Malloc<int>(FragmentCounter, "KeySetsContainer::ParseKeySets: *RowCounter");
   for(int i=0;(i<FragmentCounter) && (!input.eof());i++) {
     stringstream line;
     AtomCounter[i] = ACounter[i];
     // parse the values
-    KeySets[i] = (int *) Malloc(sizeof(int)*AtomCounter[i], "KeySetsContainer::ParseKeySets: *KeySets[]");
+    KeySets[i] = Malloc<int>(AtomCounter[i], "KeySetsContainer::ParseKeySets: *KeySets[]");
     for(int j=AtomCounter[i];j--;)
       KeySets[i][j] = -1;
     FragmentNumber = FixedDigitNumber(FragmentCounter, i);
     //cout << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:";
-    Free((void **)&FragmentNumber, "KeySetsContainer::ParseKeySets: *FragmentNumber");
+    Free(&FragmentNumber);
     input.getline(filename, 1023);
     line.str(filename);
@@ -1047,5 +1048,5 @@
 
   // scan through all to determine fragments per order
-  FragmentsPerOrder = (int *) Malloc(sizeof(int)*Order, "KeySetsContainer::ParseManyBodyTerms: *FragmentsPerOrder");
+  FragmentsPerOrder = Malloc<int>(Order, "KeySetsContainer::ParseManyBodyTerms: *FragmentsPerOrder");
   for(int i=Order;i--;)
     FragmentsPerOrder[i] = 0;
@@ -1061,7 +1062,7 @@
 
   // scan through all to gather indices to each order set
-  OrderSet = (int **) Malloc(sizeof(int *)*Order, "KeySetsContainer::ParseManyBodyTerms: **OrderSet");
+  OrderSet = Malloc<int*>(Order, "KeySetsContainer::ParseManyBodyTerms: **OrderSet");
   for(int i=Order;i--;)
-    OrderSet[i] = (int *) Malloc(sizeof(int)*FragmentsPerOrder[i], "KeySetsContainer::ParseManyBodyTermsKeySetsContainer::ParseManyBodyTerms: *OrderSet[]");
+    OrderSet[i] = Malloc<int>(FragmentsPerOrder[i], "KeySetsContainer::ParseManyBodyTermsKeySetsContainer::ParseManyBodyTerms: *OrderSet[]");
   for(int i=Order;i--;)
     FragmentsPerOrder[i] = 0;
Index: src/stackclass.hpp
===================================================================
--- src/stackclass.hpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/stackclass.hpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -3,4 +3,5 @@
 
 #include "verbose.hpp"
+#include "memoryallocator.hpp"
 
 template <typename T> class StackClass;
@@ -43,5 +44,5 @@
   NextFreeField = 0;
   EntryCount = dimension;
-  StackList = (T *) Malloc(sizeof(T)*EntryCount, "StackClass::StackClass: **StackList");
+  StackList = Malloc<T>(EntryCount, "StackClass::StackClass: **StackList");
 };
 
@@ -50,5 +51,5 @@
 template <typename T> StackClass<T>::~StackClass()
 {
-  Free((void **)&StackList, "StackClass::StackClass: **StackList");
+  Free(&StackList);
 };
 
Index: src/tesselation.cpp
===================================================================
--- src/tesselation.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/tesselation.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -7,4 +7,5 @@
 
 #include "tesselation.hpp"
+#include "memoryallocator.hpp"
 
 // ======================================== Points on Boundary =================================
@@ -504,5 +505,5 @@
 TesselPoint::~TesselPoint()
 {
-  Free((void **)&Name, "TesselPoint::~TesselPoint: *Name");
+  Free(&Name);
 };
 
Index: src/vector.cpp
===================================================================
--- src/vector.cpp	(revision 89c8b25b009146faf28147259d014f97a6f3c327)
+++ src/vector.cpp	(revision 29812d568aaa49fa5ca9e12066f70b95b8cfe954)
@@ -8,4 +8,5 @@
 #include "defs.hpp"
 #include "helpers.hpp"
+#include "memoryallocator.hpp"
 #include "leastsquaremin.hpp"
 #include "vector.hpp"
@@ -674,5 +675,5 @@
 double * Vector::InverseMatrix(double *A)
 {
-  double *B = (double *) Malloc(sizeof(double)*NDIM*NDIM, "Vector::InverseMatrix: *B");
+  double *B = Malloc<double>(NDIM * NDIM, "Vector::InverseMatrix: *B");
   double detA = RDET3(A);
   double detAReci;
