Index: src/Fragmentation/AdaptivityMap.cpp
===================================================================
--- src/Fragmentation/AdaptivityMap.cpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/AdaptivityMap.cpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -155,5 +155,5 @@
     if (Walker != NULL) {
       //if ((*runner).second.second >= Walker->AdaptiveOrder) { // only insert if this is an "active" root site for the current order
-      if (!Walker->MaxOrder) {
+      if (Walker->MaxOrder > Walker->AdaptiveOrder) {
         LOG(2, "(" << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "])");
         FinalRootCandidates->insert( make_pair( (*runner).second.first, pair<int,int>((*runner).first, (*runner).second.second) ) );
Index: src/Fragmentation/BondsPerShortestPath.cpp
===================================================================
--- src/Fragmentation/BondsPerShortestPath.cpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/BondsPerShortestPath.cpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -100,6 +100,6 @@
 {
   LOG(0, "Free'ing all found lists and resetting index lists");
-  std::stringstream output;
   for(int i=Order;i--;) {
+    std::stringstream output;
     output << "Current SP level is " << i << ": ";
     // delete added bonds
@@ -114,6 +114,6 @@
     // also start and end node
     output << "cleaned.";
-  }
-  LOG(1, output.str());
+    LOG(1, output.str());
+  }
 };
 
@@ -204,5 +204,5 @@
         Binder != BondsPerSPList[i].end();
         ++Binder) {
-      LOG(2, *Binder);
+      LOG(2, **Binder);
     }
   }
@@ -223,11 +223,2 @@
   return SP;
 };
-
-/** Getter for BondsPerShortestPath::Order.
- *
- * @return returns BondsPerShortestPath::Order
- */
-int BondsPerShortestPath::getOrder() const
-{
-  return Order;
-}
Index: src/Fragmentation/BondsPerShortestPath.hpp
===================================================================
--- src/Fragmentation/BondsPerShortestPath.hpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/BondsPerShortestPath.hpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -50,4 +50,16 @@
 };
 
+/** Getter for BondsPerShortestPath::Order.
+ *
+ * @return returns BondsPerShortestPath::Order
+ */
+#ifdef HAVE_INLINE
+inline
+#endif
+int BondsPerShortestPath::getOrder() const
+{
+  return Order;
+}
+
 
 #endif /* BONDSPERSHORTESTPATH_HPP_ */
Index: src/Fragmentation/Fragmentation.cpp
===================================================================
--- src/Fragmentation/Fragmentation.cpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/Fragmentation.cpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -200,5 +200,5 @@
 {
   Info FunctionInfo(__func__);
-  Graph ***FragmentLowerOrdersList = NULL;
+  std::vector<Graph*> *FragmentLowerOrdersList = NULL;
   int NumLevels = 0;
   int NumMolecules = 0;
@@ -210,17 +210,12 @@
   int RootKeyNr = 0;
   int RootNr = 0;
-  UniqueFragments FragmentSearch;
 
   // 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 = new int[UpgradeCount];
-  FragmentLowerOrdersList = new Graph**[UpgradeCount];
-
-  for(int i=0;i<UpgradeCount;i++) {
+  FragmentLowerOrdersList = new std::vector<Graph*>[UpgradeCount];
+
+  for(int i=0;i<UpgradeCount;i++)
     NumMoleculesOfOrder[i] = 0;
-    FragmentLowerOrdersList[i] = NULL;
-  }
-
-  FragmentSearch.Init(mol->FindAtom(RootKeyNr));
 
   // Construct the complete KeySet which we need for topmost level only (but for all Roots)
@@ -244,24 +239,23 @@
     //} else
     {
-      // increase adaptive order by one
-      Walker->GetTrueFather()->AdaptiveOrder++;
+      // set adaptive order to desired max order
+      Walker->GetTrueFather()->AdaptiveOrder = Walker->GetTrueFather()->MaxOrder;
       Order = Walker->AdaptiveOrder = Walker->GetTrueFather()->AdaptiveOrder;
 
+      // allocate memory for all lower level orders
+      NumLevels = Order;
+      FragmentLowerOrdersList[RootNr].resize(NumLevels, NULL);
+      for( size_t i=0;i<NumLevels;++i)
+        FragmentLowerOrdersList[RootNr][i] = new Graph;
+
       // initialise Order-dependent entries of UniqueFragments structure
-      class PowerSetGenerator PSG(&FragmentSearch, Walker->AdaptiveOrder);
-
-      // allocate memory for all lower level orders in this 1D-array of ptrs
-      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
-      FragmentLowerOrdersList[RootNr] = new Graph*[NumLevels];
-      for (int i=0;i<NumLevels;i++)
-        FragmentLowerOrdersList[RootNr][i] = NULL;
+      UniqueFragments FragmentSearch(1., FragmentLowerOrdersList[RootNr], Walker);
+      PowerSetGenerator PSG(&FragmentSearch, Walker->AdaptiveOrder);
 
       // create top order where nothing is reduced
       LOG(0, "==============================================================================================================");
-      LOG(0, "Creating KeySets of Bond Order " << Order << " for " << *Walker << ", " << (RootStack.size()-RootNr) << " Roots remaining."); // , NumLevels is " << NumLevels << "
+      LOG(0, "Creating KeySets up till Bond Order " << Order << " for " << *Walker << ", " << (RootStack.size()-RootNr) << " Roots remaining."); // , NumLevels is " << NumLevels << "
 
       // Create list of Graphs of current Bond Order (i.e. F_{ij})
-      FragmentLowerOrdersList[RootNr][0] = new Graph;
-      FragmentSearch.PrepareForPowersetGeneration(1., FragmentLowerOrdersList[RootNr][0], Walker);
       NumMoleculesOfOrder[RootNr] = PSG(CompleteMolecule, saturation);
 
@@ -270,6 +264,4 @@
       if (NumMoleculesOfOrder[RootNr] != 0) {
         NumMolecules = 0;
-      } else {
-        Walker->GetTrueFather()->MaxOrder = true;
       }
       // now, we have completely filled each cell of FragmentLowerOrdersList[] for the current Walker->AdaptiveOrder
@@ -284,7 +276,4 @@
   LOG(1, "Total number of resulting molecules is: " << TotalNumMolecules << ".");
   LOG(0, "==============================================================================================================");
-
-  // cleanup FragmentSearch structure
-  FragmentSearch.Cleanup();
 
   // now, FragmentLowerOrdersList is complete, it looks - for BondOrder 5 - as this (number is the ANOVA Order of the terms therein)
@@ -362,8 +351,9 @@
     delete[](IndexKeySetList);
   } else { // global increase of Bond Order
-    for(molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
+    for(molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
       if (AtomMask.isTrue((*iter)->getNr())) { // skip masked out
+        (*iter)->MaxOrder = (Order != 0 ? Order : (*iter)->MaxOrder+1);
         // remove all that have reached desired order
-        if ((Order != 0) && ((*iter)->AdaptiveOrder >= Order)) // && ((*iter)->AdaptiveOrder < MinimumRingSize[(*iter)->getNr()]))
+        if ((*iter)->AdaptiveOrder >= (*iter)->MaxOrder) // && ((*iter)->AdaptiveOrder < MinimumRingSize[(*iter)->getNr()]))
           AtomMask.setFalse((*iter)->getNr());
         else
@@ -450,5 +440,5 @@
     for(molecule::iterator iter=mol->begin();iter!=mol->end();++iter){
       (*iter)->AdaptiveOrder = OrderArray[(*iter)->getNr()];
-      (*iter)->MaxOrder = MaxArray.isTrue((*iter)->getNr());
+      (*iter)->MaxOrder = OrderArray[(*iter)->getNr()]; //MaxArray.isTrue((*iter)->getNr());
     }
     //SetAtomValueToIndexedArray( OrderArray, &atom::getNr(), &atom::AdaptiveOrder );
Index: src/Fragmentation/PowerSetGenerator.cpp
===================================================================
--- src/Fragmentation/PowerSetGenerator.cpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/PowerSetGenerator.cpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -50,6 +50,6 @@
  *
  */
-PowerSetGenerator::PowerSetGenerator(class UniqueFragments *_FragmentSearch, int Order) :
-  BondsPerSPList(Order),
+PowerSetGenerator::PowerSetGenerator(UniqueFragments *_FragmentSearch, int _Order) :
+  BondsPerSPList(_Order),
   FragmentSearch(_FragmentSearch)
 {}
@@ -213,5 +213,5 @@
   int SP = BondsPerSPList.CountNumbersInBondsList();
   LOG(0, "Total number of edges is " << SP << ".");
-  if (SP >= (BondsPerSPList.getOrder()-1)) {
+  {
     // start with root (push on fragment stack)
     LOG(0, "Starting fragment generation with " << *FragmentSearch->getRoot() << ", local nr is " << FragmentSearch->getRoot()->getNr() << ".");
@@ -227,6 +227,4 @@
 
     SPFragmentGenerator(0, BondsList, BondsPerSPList.BondsPerSPCount[0], BondsPerSPList.getOrder());
-  } else {
-    LOG(0, "Not enough total number of edges to build " << BondsPerSPList.getOrder() << "-body fragments.");
   }
 
@@ -261,11 +259,10 @@
   Info info(__func__);
   int verbosity = 0; //FragmentSearch->ANOVAOrder-SubOrder;
-  int NumCombinations;
-  int bits, TouchedIndex, SubSetDimension, SP, Added;
+  int TouchedIndex, SubSetDimension, Added;
   int SpaceLeft;
   int *TouchedList = new int[SubOrder + 1];
   KeySetTestPair TestKeySetInsert;
 
-  NumCombinations = 1 << SetDimension;
+  const int NumCombinations = 1 << SetDimension;
 
   // here for all bonds of Walker all combinations of end pieces (from the bonds)
@@ -282,7 +279,5 @@
   for (int i=1;i<NumCombinations;i++) {  // sweep through all power set combinations (skip empty set!)
     // count the set bit of i
-    bits = 0;
-    for (int j=SetDimension;j--;)
-      bits += (i & (1 << j)) >> j;
+    const int bits = countBits(i, SetDimension);
 
     LOG(1+verbosity, "Current set is " << Binary(i | (1 << SetDimension)) << ", number of bits is " << bits << ".");
@@ -291,10 +286,24 @@
       Added = AddPowersetToSnakeStack(verbosity, i, SetDimension, FragmentSearch->FragmentSet, BondsSet, TouchedList, TouchedIndex);
 
+      // --2-- store the fragment
+      const int order = BondsPerSPList.getOrder() - SubOrder + Added - 1;
+      LOG(1+verbosity, "Storing fragment as order " << order << ".");
+      // store fragment as a KeySet
+      if (DoLog(2)) {
+        std::stringstream output;
+        output << "Found a new fragment[" << FragmentSearch->FragmentCounter << "], local nr.s are: ";
+        for(KeySet::iterator runner = FragmentSearch->FragmentSet->begin(); runner != FragmentSearch->FragmentSet->end(); runner++)
+          output << (*runner) << " ";
+        LOG(2, output.str());
+      }
+      FragmentSearch->InsertFragmentIntoGraph(order);
+
+      // --3-- if below SubOrder still, recurse
       SpaceLeft = SubOrder - Added ;// SubOrder - bits; // due to item's maybe being already present, this does not work anymore
-      if (SpaceLeft > 0) {
+      if ((SpaceLeft > 0) && (RootDistance < BondsPerSPList.getOrder())) {
         LOG(1+verbosity, "There's still some space left on stack: " << SpaceLeft << ".");
         if (SubOrder > 1) {    // Due to Added above we have to check extra whether we're not already reaching beyond the desired Order
           // --2-- look at all added end pieces of this combination, construct bond subsets and sweep through a power set of these by recursion
-          SP = RootDistance+1;  // this is the next level
+          const int SP = RootDistance+1;  // this is the next level
 
           // first count the members in the subset
@@ -311,15 +320,5 @@
         }
       } else {
-        // --2-- otherwise store the complete fragment
-        LOG(1+verbosity, "Enough items on stack for a fragment!");
-        // store fragment as a KeySet
-        if (DoLog(2)) {
-          std::stringstream output;
-          output << "Found a new fragment[" << FragmentSearch->FragmentCounter << "], local nr.s are: ";
-          for(KeySet::iterator runner = FragmentSearch->FragmentSet->begin(); runner != FragmentSearch->FragmentSet->end(); runner++)
-            output << (*runner) << " ";
-          LOG(2, output.str());
-        }
-        FragmentSearch->InsertFragmentIntoGraph();
+        LOG(1+verbosity, "No more space or no shortest path levels, not recursing.");
       }
 
Index: src/Fragmentation/PowerSetGenerator.hpp
===================================================================
--- src/Fragmentation/PowerSetGenerator.hpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/PowerSetGenerator.hpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -26,5 +26,5 @@
 {
 public:
-  PowerSetGenerator(UniqueFragments *_FragmentSearch, int Order);
+  PowerSetGenerator(UniqueFragments *_FragmentSearch, int _Order);
   ~PowerSetGenerator();
 
@@ -38,8 +38,20 @@
 
 private:
+  int countBits(const int bits, const int SetDimension) const;
+
   BondsPerShortestPath BondsPerSPList;
+  UniqueFragments *FragmentSearch;
+};
 
-  class UniqueFragments *FragmentSearch;
-};
+#ifdef HAVE_INLINE
+inline
+#endif
+int PowerSetGenerator::countBits(const int i, const int SetDimension) const
+{
+  int bits = 0;
+  for (int j=SetDimension;j--;)
+    bits += (i & (1 << j)) >> j;
+  return bits;
+}
 
 
Index: src/Fragmentation/UniqueFragments.cpp
===================================================================
--- src/Fragmentation/UniqueFragments.cpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/UniqueFragments.cpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -37,4 +37,5 @@
 #include "UniqueFragments.hpp"
 
+#include "CodePatterns/Assert.hpp"
 #include "CodePatterns/Log.hpp"
 
@@ -48,7 +49,16 @@
 /** Constructor of class UniqueFragments.
  *
+ * @param _TEFactor total energy factor
+ * @param _Leaflet current graph to work on
+ * @param _Root root atom
  */
-UniqueFragments::UniqueFragments()
-{}
+UniqueFragments::UniqueFragments(double _TEFactor, std::vector<Graph*> &_Leaflets, atom *_Root) :
+    FragmentCounter(0),
+    Root(_Root),
+    TEFactor(_TEFactor),
+    Leaflets(_Leaflets)
+{
+  FragmentSet = new KeySet;
+}
 
 /** Destructor of class UniqueFragments.
@@ -56,13 +66,20 @@
  */
 UniqueFragments::~UniqueFragments()
-{}
+{
+  Cleanup();
+}
 
 /** Checking whether KeySet is not already present in Graph, if so just adds factor.
+ *
+ * \param order order at which to insert
  */
-void UniqueFragments::InsertFragmentIntoGraph()
+void UniqueFragments::InsertFragmentIntoGraph(const size_t order)
 {
   GraphTestPair testGraphInsert;
 
-  testGraphInsert = Leaflet->insert(GraphPair (*FragmentSet,std::pair<int,double>(FragmentCounter,TEFactor)));  // store fragment number and current factor
+  ASSERT( Leaflets.size() > order,
+      "UniqueFragments::InsertFragmentIntoGraph() - Leaflets has only "
+      +toString(Leaflets.size())+" entries, not enough for "+toString(order));
+  testGraphInsert = Leaflets[order]->insert(GraphPair (*FragmentSet,std::pair<int,double>(FragmentCounter,TEFactor)));  // store fragment number and current factor
   if (testGraphInsert.second) {
     LOG(2, "KeySet " << FragmentCounter << " successfully inserted.");
@@ -75,17 +92,4 @@
 };
 
-/** Initialization for UniqueFragments.
- *
- * \param _Root ref to atom to start from (with graph algorithms, hence root node)
- * \param AtomCount number of nodes/atoms
- */
-void UniqueFragments::Init(atom *_Root)
-{
-  // initialise the fragments structure
-  FragmentCounter = 0;
-  FragmentSet = new KeySet;
-  Root = _Root;
-}
-
 /** Removes some allocated memory.
  *
@@ -93,5 +97,5 @@
 void UniqueFragments::Cleanup()
 {
-  delete(FragmentSet);
+  delete FragmentSet;
 }
 
@@ -113,15 +117,2 @@
   Root=_root;
 }
-
-/** Sets initial values before PowerSetGenerator uses this class.
- *
- * @param _TEFactor total energy factor
- * @param _Leaflet current graph to work on
- * @param _Root root atom
- */
-void UniqueFragments::PrepareForPowersetGeneration(double _TEFactor, Graph *_Leaflet, atom *_Root)
-{
-  TEFactor = _TEFactor;
-  Leaflet = _Leaflet;
-  Root = _Root;
-}
Index: src/Fragmentation/UniqueFragments.hpp
===================================================================
--- src/Fragmentation/UniqueFragments.hpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/UniqueFragments.hpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -14,10 +14,7 @@
 #endif
 
-#include <list>
 #include <vector>
 
 class atom;
-class bond;
-class config;
 class Graph;
 class KeySet;
@@ -28,15 +25,15 @@
 {
 public:
-  UniqueFragments();
+  UniqueFragments(
+      double _TEFactor,
+      std::vector<Graph*> &Leaflets,
+      atom *_Root);
   ~UniqueFragments();
 
-  void InsertFragmentIntoGraph(); // Insert a KeySet into a Graph
-  void Init(atom *_Root);
+  void InsertFragmentIntoGraph(const size_t order); // Insert a KeySet into a Graph
   void Cleanup();
 
   atom * const getRoot() const;
   void setRoot(atom *_root);
-
-  void PrepareForPowersetGeneration(double _TEFactor, Graph *_Leaflet, atom *_Root);
 
   KeySet *FragmentSet;
@@ -46,10 +43,5 @@
   atom *Root;
   double TEFactor;
-  Graph *Leaflet;
-
-private:
-  int ANOVAOrder;
-  int CurrentIndex;
-  bool **UsedList;
+  std::vector<Graph*> &Leaflets;
 };
 
Index: src/Fragmentation/fragmentation_helpers.cpp
===================================================================
--- src/Fragmentation/fragmentation_helpers.cpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/fragmentation_helpers.cpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -37,11 +37,11 @@
 #include "fragmentation_helpers.hpp"
 
+#include <algorithm>
 #include <sstream>
 
+#include "CodePatterns/Assert.hpp"
 #include "CodePatterns/Log.hpp"
 
 #include "Atom/atom.hpp"
-#include "Bond/bond.hpp"
-#include "Element/element.hpp"
 #include "Fragmentation/AdaptivityMap.hpp"
 #include "Fragmentation/AtomMask.hpp"
@@ -82,5 +82,5 @@
  * \param *mol molecule with atoms and bonds
  */
-int CombineAllOrderListIntoOne(Graph &FragmentList, Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol)
+int CombineAllOrderListIntoOne(Graph &FragmentList, std::vector<Graph*> *&FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol)
 {
   int RootNr = 0;
@@ -99,5 +99,7 @@
     RootStack.pop_front();
     Walker = mol->FindAtom(RootKeyNr);
-    NumLevels = 1 << (Walker->AdaptiveOrder - 1);
+    NumLevels = Walker->AdaptiveOrder;
+    ASSERT( NumLevels == FragmentLowerOrdersList[RootNr].size(),
+        "CombineAllOrderListIntoOne() - differing size and NumLevels.");
     for(int i=0;i<NumLevels;i++) {
       if (FragmentLowerOrdersList[RootNr][i] != NULL) {
@@ -113,9 +115,9 @@
 /** Free's memory allocated for all KeySets from all orders.
  * \param *out output stream for debugging
- * \param ***FragmentLowerOrdersList
+ * \param **&FragmentLowerOrdersList
  * \param &RootStack stack with all root candidates (unequal to each atom in complete molecule if adaptive scheme is applied)
  * \param *mol molecule with atoms and bonds
  */
-void FreeAllOrdersList(Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol)
+void FreeAllOrdersList(std::vector<Graph*> *&FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol)
 {
   LOG(1, "Free'ing the lists of all orders per order.");
@@ -128,14 +130,14 @@
     RootStack.pop_front();
     Walker = mol->FindAtom(RootKeyNr);
-    NumLevels = 1 << (Walker->AdaptiveOrder - 1);
+    NumLevels = Walker->AdaptiveOrder;
     for(int i=0;i<NumLevels;i++) {
       if (FragmentLowerOrdersList[RootNr][i] != NULL) {
-        delete(FragmentLowerOrdersList[RootNr][i]);
+        delete FragmentLowerOrdersList[RootNr][i];
       }
+      FragmentLowerOrdersList[RootNr].clear();
     }
-    delete[](FragmentLowerOrdersList[RootNr]);
     RootNr++;
   }
-  delete[](FragmentLowerOrdersList);
+  delete[] FragmentLowerOrdersList;
 };
 
Index: src/Fragmentation/fragmentation_helpers.hpp
===================================================================
--- src/Fragmentation/fragmentation_helpers.hpp	(revision 4a77be7c74807798597478c1e2a88d09178390fe)
+++ src/Fragmentation/fragmentation_helpers.hpp	(revision d760bb7f23671603e1c139dfb961473ce290ff50)
@@ -15,7 +15,4 @@
 
 #include <deque>
-#include <list>
-#include <map>
-#include <string>
 #include <vector>
 
@@ -31,6 +28,6 @@
 void PrintAtomMask(const AtomMask_t &AtomMask, int AtomCount);
 
-int CombineAllOrderListIntoOne(Graph &FragmentList, Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol);
-void FreeAllOrdersList(Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol);
+int CombineAllOrderListIntoOne(Graph &FragmentList, std::vector<Graph*> *&FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol);
+void FreeAllOrdersList(std::vector<Graph*> *&FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol);
 
 const std::vector<atomId_t> getGlobalIdsFromLocalIds(const molecule &mol, const std::vector<atomId_t> &atomids);
