Index: src/molecule_graph.cpp
===================================================================
--- src/molecule_graph.cpp	(revision ce7cc5a8c3093070a9f2372212477b11f78c01b0)
+++ src/molecule_graph.cpp	(revision 43587e21efd075291b9296d09704c14839147781)
@@ -1154,31 +1154,19 @@
 };
 
-
-/** Adds bond structure to this molecule from \a Father molecule.
- * This basically causes this molecule to become an induced subgraph of the \a Father, i.e. for every bond in Father
- * with end points present in this molecule, bond is created in this molecule.
- * Special care was taken to ensure that this is of complexity O(N), where N is the \a Father's molecule::AtomCount.
- * \param *out output stream for debugging
- * \param *Father father molecule
- * \return true - is induced subgraph, false - there are atoms with fathers not in \a Father
- * \todo not checked, not fully working probably
- */
-bool molecule::BuildInducedSubgraph(ofstream *out, const molecule *Father)
-{
-  atom *Walker = NULL, *OtherAtom = NULL;
-  bool status = true;
-  atom **ParentList = Malloc<atom*>(Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
-
-  *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
-
+void BuildInducedSubgraph_Init(ofstream *out, atom **&ParentList, int AtomCount)
+{
   // reset parent list
+  ParentList = Malloc<atom*>(AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
   *out << Verbose(3) << "Resetting ParentList." << endl;
-  for (int i=Father->AtomCount;i--;)
+  for (int i=AtomCount;i--;)
     ParentList[i] = NULL;
-
+};
+
+void BuildInducedSubgraph_FillParentList(ofstream *out, const molecule *mol, const molecule *Father, atom **&ParentList)
+{
   // fill parent list with sons
   *out << Verbose(3) << "Filling Parent List." << endl;
-  Walker = start;
-  while (Walker->next != end) {
+  atom *Walker = mol->start;
+  while (Walker->next != mol->end) {
     Walker = Walker->next;
     ParentList[Walker->father->nr] = Walker;
@@ -1187,4 +1175,16 @@
   }
 
+};
+
+void BuildInducedSubgraph_Finalize(ofstream *out, atom **&ParentList)
+{
+  Free(&ParentList);
+};
+
+bool BuildInducedSubgraph_CreateBondsFromParent(ofstream *out, molecule *mol, const molecule *Father, atom **&ParentList)
+{
+  bool status = true;
+  atom *Walker = NULL;
+  atom *OtherAtom = NULL;
   // check each entry of parent list and if ok (one-to-and-onto matching) create bonds
   *out << Verbose(3) << "Creating bonds." << endl;
@@ -1200,5 +1200,5 @@
           if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond
             *out << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl;
-            AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);
+            mol->AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);
           }
         }
@@ -1206,6 +1206,26 @@
     }
   }
-
-  Free(&ParentList);
+  return status;
+};
+
+/** Adds bond structure to this molecule from \a Father molecule.
+ * This basically causes this molecule to become an induced subgraph of the \a Father, i.e. for every bond in Father
+ * with end points present in this molecule, bond is created in this molecule.
+ * Special care was taken to ensure that this is of complexity O(N), where N is the \a Father's molecule::AtomCount.
+ * \param *out output stream for debugging
+ * \param *Father father molecule
+ * \return true - is induced subgraph, false - there are atoms with fathers not in \a Father
+ * \todo not checked, not fully working probably
+ */
+bool molecule::BuildInducedSubgraph(ofstream *out, const molecule *Father)
+{
+  bool status = true;
+  atom **ParentList = NULL;
+
+  *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
+  BuildInducedSubgraph_Init(out, ParentList, Father->AtomCount);
+  BuildInducedSubgraph_FillParentList(out, this, Father, ParentList);
+  status = BuildInducedSubgraph_CreateBondsFromParent(out, this, Father, ParentList);
+  BuildInducedSubgraph_Finalize(out, ParentList);
   *out << Verbose(2) << "End of BuildInducedSubgraph." << endl;
   return status;
