Index: src/moleculelist.cpp
===================================================================
--- src/moleculelist.cpp	(revision 85bac07a96bad99841916279c5887226effb9305)
+++ src/moleculelist.cpp	(revision 41f151252894d0d3731a46b364f36e7364983553)
@@ -589,13 +589,13 @@
     while (Walker->next != Leaf->end) {
       Walker = Walker->next;
-      AtomNo = Walker->father->nr;  // global id of the current walker
+      AtomNo = Walker->GetTrueFather()->nr;  // global id of the current walker
       for(int i=0;i<reference->NumberOfBondsPerAtom[AtomNo];i++) { // go through father's bonds and copy them all
         Binder = reference->ListOfBondsPerAtom[AtomNo][i];
-        OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->father)->nr];    // local copy of current bond partner of walker
+        OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->GetTrueFather())->nr];    // local copy of current bond partner of walker
         if (OtherWalker != NULL) {
           if (OtherWalker->nr > Walker->nr)
           Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree);
         } else {
-          *out << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << Binder->GetOtherAtom(Walker->father)->nr << "] is NULL!" << endl;
+          *out << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << Binder->GetOtherAtom(Walker->GetTrueFather())->nr << "] is NULL!" << endl;
           status = false;
         }
@@ -608,8 +608,9 @@
   }
   
+  FragmentCounter--;
   if (FreeList) {
     // free the index lookup list
     Free((void **)&ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::FillBondStructureFromReference - **ListOfLocalAtoms[]");
-    if (ListOfLocalAtoms[FragmentCounter] == NULL)
+    if (FragmentCounter == 0) // first fragments frees the initial pointer to list
       Free((void **)&ListOfLocalAtoms, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
   }
@@ -661,10 +662,10 @@
  * \param *out output stream fro debugging
  * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
- * \param &FragmentCounter counts the fragments as we move along the list
+ * \param FragmentCounter counts the fragments as we move along the list
  * \param GlobalAtomCount number of atoms in the complete molecule
  * \param &FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
  * \return true - succes, false - failure
  */
-bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, int &FragmentCounter, int GlobalAtomCount, bool &FreeList)
+bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList)
 {
   bool status = true;
@@ -726,5 +727,5 @@
     KeySet *TempSet = new KeySet;
     for(Graph::iterator runner = KeySetList->begin();runner != KeySetList->end(); runner++) { // key sets contain global numbers!
-      if ( ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*((*runner).first.begin()))->nr]->nr != -1) {// as we may assume that that bond structure is unchanged, we only test the first key in each set
+      if ( ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*((*runner).first.begin()))->nr] != NULL) {// as we may assume that that bond structure is unchanged, we only test the first key in each set
         // translate keyset to local numbers
         for(KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
@@ -744,8 +745,14 @@
     if (next != NULL)
       next->AssignKeySetsToFragment(out, reference, KeySetList, ListOfLocalAtoms, FragmentList, FragmentCounter, FreeList);
-    FragmentCounter--;
   } else
     *out << Verbose(1) << "KeySetList is NULL or empty." << endl;
   
+  FragmentCounter--;
+  if (FreeList) {
+    // free the index lookup list
+    Free((void **)&ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::AssignKeySetsToFragment - **ListOfLocalAtoms[]");
+    if (FragmentCounter == 0) // first fragments frees the initial pointer to list
+      Free((void **)&ListOfLocalAtoms, "MoleculeLeafClass::AssignKeySetsToFragment - ***ListOfLocalAtoms");
+  }
   return status;
 };
