Index: src/Fragmentation/Interfragmenter.cpp
===================================================================
--- src/Fragmentation/Interfragmenter.cpp	(revision 7537d191a569f0b72f4ef6db9b9ae70d575a463f)
+++ src/Fragmentation/Interfragmenter.cpp	(revision 0d90534c2cfcca7121d5161e6f235225bdb4c0df)
@@ -37,7 +37,4 @@
 #include "Interfragmenter.hpp"
 
-#include <list>
-#include <map>
-
 #include "CodePatterns/Assert.hpp"
 #include "CodePatterns/Log.hpp"
@@ -45,5 +42,4 @@
 #include "LinearAlgebra/Vector.hpp"
 
-#include "AtomIdSet.hpp"
 #include "Element/element.hpp"
 #include "Fragmentation/Graph.hpp"
@@ -53,12 +49,10 @@
 #include "World.hpp"
 
-void Interfragmenter::operator()(
-    size_t MaxOrder,
-    double Rcut,
-    const enum HydrogenTreatment treatment)
+
+Interfragmenter::atomkeyset_t Interfragmenter::getAtomKeySetMap(
+    size_t _MaxOrder
+    ) const
 {
   /// create a map of atom to keyset (below equal MaxOrder)
-  typedef std::list<const KeySet *> keysets_t;
-  typedef std::map<const atom *, keysets_t > atomkeyset_t;
   atomkeyset_t atomkeyset;
   LOG(1, "INFO: Placing all atoms and their keysets into a map.");
@@ -69,5 +63,5 @@
     const AtomIdSet atoms(keyset);
     const size_t atoms_size = atoms.getAtomIds().size();
-    if ((atoms_size > MaxOrder) || (atoms_size == 0))
+    if ((atoms_size > _MaxOrder) || (atoms_size == 0))
       continue;
     for (AtomIdSet::const_iterator atomiter = atoms.begin();
@@ -87,4 +81,118 @@
   LOG(2, "DEBUG: There are " << atomkeyset.size() << " entries in lookup.");
 
+  return atomkeyset;
+}
+
+static Vector getAtomIdSetCenter(
+    const AtomIdSet &_atoms)
+{
+  const molecule * const _mol = (*_atoms.begin())->getMolecule();
+  const size_t atoms_size = _atoms.getAtomIds().size();
+  Vector center;
+  for (AtomIdSet::const_iterator iter = _atoms.begin();
+      iter != _atoms.end(); ++iter) {
+    center += (*iter)->getPosition();
+    ASSERT ( _mol == (*iter)->getMolecule(),
+        "getAtomIdSetCenter() - ids in same keyset belong to different molecule.");
+  }
+  center *= 1./(double)atoms_size;
+
+  return center;
+}
+
+Interfragmenter::candidates_t Interfragmenter::getNeighborsOutsideMolecule(
+    const AtomIdSet &_atoms,
+    double _Rcut,
+    const enum HydrogenTreatment _treatment) const
+{
+  /// go through linked cell and get all neighboring atoms up to Rcut
+  const LinkedCell::LinkedCell_View view = World::getInstance().getLinkedCell(_Rcut);
+  const Vector center = getAtomIdSetCenter(_atoms);
+  const LinkedCell::LinkedList neighbors = view.getAllNeighbors(_Rcut, center);
+  LOG(4, "DEBUG: Obtained " << neighbors.size() << " neighbors in distance of "
+      << _Rcut << " around " << center << ".");
+
+  /// remove all atoms that belong to same molecule as does one of the
+  /// fragment's atoms
+  const molecule * const _mol = (*_atoms.begin())->getMolecule();
+  candidates_t candidates;
+  candidates.reserve(neighbors.size());
+  for (LinkedCell::LinkedList::const_iterator iter = neighbors.begin();
+      iter != neighbors.end(); ++iter) {
+    const atom * const _atom = static_cast<const atom * const >(*iter);
+    ASSERT( _atom != NULL,
+        "Interfragmenter::getNeighborsOutsideMolecule() - a neighbor is not actually an atom?");
+    if ((_atom->getMolecule() != _mol)
+        && (_atom->getPosition().DistanceSquared(center) < _Rcut*_Rcut)
+        && ((_treatment == IncludeHydrogen) || (_atom->getType()->getAtomicNumber() != 1))) {
+      candidates.push_back(_atom);
+    }
+  }
+  LOG(3, "DEBUG: There remain " << candidates.size() << " candidates.");
+
+  return candidates;
+}
+
+Interfragmenter::atomkeyset_t Interfragmenter::getCandidatesSpecificKeySetMap(
+    const candidates_t &_candidates,
+    const atomkeyset_t &_atomkeyset) const
+{
+  atomkeyset_t fragmentmap;
+  for (candidates_t::const_iterator candidateiter = _candidates.begin();
+      candidateiter != _candidates.end(); ++candidateiter) {
+    const atom * _atom = *candidateiter;
+    atomkeyset_t::const_iterator iter = _atomkeyset.find(_atom);
+    ASSERT( iter != _atomkeyset.end(),
+        "Interfragmenter::getAtomSpecificKeySetMap() - could not find atom "
+        +toString(_atom->getId())+" in lookup.");
+    fragmentmap.insert( std::make_pair( _atom, iter->second) );
+  }
+  LOG(4, "DEBUG: Copied part of lookup map contains " << fragmentmap.size() << " keys.");
+
+  return fragmentmap;
+}
+
+void Interfragmenter::combineFragments(
+    const candidates_t &_candidates,
+    atomkeyset_t &_fragmentmap,
+    const KeySet &_keyset,
+    Graph &_InterFragments,
+    int &_counter)
+{
+  for (candidates_t::const_iterator candidateiter = _candidates.begin();
+      candidateiter != _candidates.end(); ++candidateiter) {
+    const atom *_atom = *candidateiter;
+    LOG(3, "DEBUG: Current candidate is " << *_atom << ".");
+    atomkeyset_t::iterator finditer = _fragmentmap.find(_atom);
+    ASSERT( finditer != _fragmentmap.end(),
+        "Interfragmenter::combineFragments() - could not find atom "
+        +toString(_atom->getId())+" in fragment specific lookup.");
+    keysets_t &othersets = finditer->second;
+    keysets_t::iterator otheriter = othersets.begin();
+    while (otheriter != othersets.end()) {
+      const KeySet &otherset = **otheriter;
+      LOG(3, "DEBUG: Current keyset is " << otherset << ".");
+      // only add them one way round and not the other
+      if (otherset < _keyset) {
+        ++otheriter;
+        continue;
+      }
+      KeySet newset(otherset);
+      newset.insert(_keyset.begin(), _keyset.end());
+      LOG(3, "DEBUG: Inserting new combined set " << newset << ".");
+      _InterFragments.insert( std::make_pair(newset, std::make_pair(++_counter, 1.)));
+      // finally, remove the set such that no other combination exists
+      otheriter = othersets.erase(otheriter);
+    }
+  }
+}
+
+void Interfragmenter::operator()(
+    const size_t MaxOrder,
+    const double Rcut,
+    const enum HydrogenTreatment treatment)
+{
+  atomkeyset_t atomkeyset = getAtomKeySetMap(MaxOrder);
+
   Graph InterFragments;
   int counter = TotalGraph.size();
@@ -101,78 +209,13 @@
       continue;
 
-    /// go through linked cell and get all neighboring atoms up to Rcut
-    Vector center;
-    const molecule *_mol = (*atoms.begin())->getMolecule();
-    for (AtomIdSet::const_iterator iter = atoms.begin();
-        iter != atoms.end(); ++iter) {
-      center += (*iter)->getPosition();
-      ASSERT ( _mol == (*iter)->getMolecule(),
-          "Interfragmenter::operator() - ids in same keyset belong to different molecule.");
-    }
-    center *= 1./(double)atoms_size;
-    LinkedCell::LinkedCell_View view = World::getInstance().getLinkedCell(Rcut);
-    LinkedCell::LinkedList neighbors = view.getAllNeighbors(Rcut, center);
-    LOG(4, "DEBUG: Obtained " << neighbors.size() << " neighbors in distance of "
-        << Rcut << " around " << center << ".");
-
-    /// remove all atoms that belong to same molecule as does one of the
-    /// fragment's atoms
-    typedef std::vector<const atom *> candidates_t;
-    candidates_t candidates;
-    candidates.reserve(neighbors.size());
-    for (LinkedCell::LinkedList::const_iterator iter = neighbors.begin();
-        iter != neighbors.end(); ++iter) {
-      const atom * const _atom = static_cast<const atom * const >(*iter);
-      ASSERT( _atom != NULL,
-          "Interfragmenter::operator() - a neighbor is not actually an atom?");
-      if ((_atom->getMolecule() != _mol)
-          && (_atom->getPosition().DistanceSquared(center) < Rcut*Rcut)
-          && ((treatment == IncludeHydrogen) || (_atom->getType()->getAtomicNumber() != 1))) {
-        candidates.push_back(_atom);
-      }
-    }
-    LOG(3, "DEBUG: There remain " << candidates.size() << " candidates.");
+    // get neighboring atoms outside the current molecule
+    candidates_t candidates = getNeighborsOutsideMolecule(atoms, Rcut, treatment);
 
     // create a lookup specific to this fragment
-    atomkeyset_t fragmentmap;
-    for (candidates_t::const_iterator candidateiter = candidates.begin();
-        candidateiter != candidates.end(); ++candidateiter) {
-      const atom * _atom = *candidateiter;
-      atomkeyset_t::const_iterator iter = atomkeyset.find(_atom);
-      ASSERT( iter != atomkeyset.end(),
-          "Interfragmenter::operator() - could not find atom "
-          +toString(_atom->getId())+" in lookup.");
-      fragmentmap.insert( std::make_pair( _atom, iter->second) );
-    }
-    LOG(4, "DEBUG: Copied part of lookup map contains " << fragmentmap.size() << " keys.");
+    atomkeyset_t fragmentmap = getCandidatesSpecificKeySetMap(candidates, atomkeyset);
 
     /// combine each remaining fragment with current fragment to a new fragment
-    /// if keyset is less
-    for (candidates_t::const_iterator candidateiter = candidates.begin();
-        candidateiter != candidates.end(); ++candidateiter) {
-      const atom *_atom = *candidateiter;
-      LOG(3, "DEBUG: Current candidate is " << *_atom << ".");
-      atomkeyset_t::iterator finditer = fragmentmap.find(_atom);
-      ASSERT( finditer != fragmentmap.end(),
-          "Interfragmenter::operator() - could not find atom "
-          +toString(_atom->getId())+" in fragment specific lookup.");
-      keysets_t &othersets = finditer->second;
-      keysets_t::iterator otheriter = othersets.begin();
-      while (otheriter != othersets.end()) {
-        const KeySet &otherset = **otheriter;
-        LOG(3, "DEBUG: Current keyset is " << otherset << ".");
-        // only add them one way round and not the other
-        if (otherset < keyset) {
-          ++otheriter;
-          continue;
-        }
-        KeySet newset(otherset);
-        newset.insert(keyset.begin(), keyset.end());
-        LOG(3, "DEBUG: Inserting new combined set " << newset << ".");
-        InterFragments.insert( std::make_pair(newset, std::make_pair(++counter, 1.)));
-        // finally, remove the set such that no other combination exists
-        otheriter = othersets.erase(otheriter);
-      }
-    }
+    /// if keyset is less (to prevent addding same inter-fragment twice)
+    combineFragments(candidates, fragmentmap, keyset, InterFragments, counter);
   }
 
Index: src/Fragmentation/Interfragmenter.hpp
===================================================================
--- src/Fragmentation/Interfragmenter.hpp	(revision 7537d191a569f0b72f4ef6db9b9ae70d575a463f)
+++ src/Fragmentation/Interfragmenter.hpp	(revision 0d90534c2cfcca7121d5161e6f235225bdb4c0df)
@@ -14,6 +14,9 @@
 #endif
 
+#include <list>
+#include <map>
 #include <vector>
 
+#include "AtomIdSet.hpp"
 #include "Fragmentation/HydrogenSaturation_enum.hpp"
 
@@ -50,6 +53,6 @@
    */
   void operator()(
-      size_t MaxOrder,
-      double Rcut,
+      const size_t MaxOrder,
+      const double Rcut,
       const enum HydrogenTreatment treatment);
 
@@ -62,4 +65,55 @@
   std::vector<atom *> getAtomsFromKeySet(const KeySet &keyset) const;
 
+  typedef std::list<const KeySet *> keysets_t;
+  typedef std::map<const atom *, keysets_t > atomkeyset_t;
+
+  /** Helper function to create a map of atoms and their fragments/keysets.
+   *
+   * \param _MaxOrder maximum order
+   * \return map with atoms as a keys and fragments as values
+   */
+  atomkeyset_t getAtomKeySetMap(size_t _MaxOrder) const;
+
+  typedef std::vector<const atom *> candidates_t;
+
+  /** Helper function to get all atoms around a specific keyset not contained in
+   * the same molecule.
+   *
+   * \param _atoms all atoms of a fragment
+   * \param _Rcut desired distance cutoff
+   * \param _treatment whether hydrogens are treated special or not
+   */
+  candidates_t getNeighborsOutsideMolecule(
+      const AtomIdSet &_atoms,
+      const double _Rcut,
+      const enum HydrogenTreatment _treatment) const;
+
+  /** Helper function to return a fragment/KeySet map specific to all candidates.
+   *
+   * \param _candidates all neighboring atoms around keyset
+   * \param _atomkeyset map with all atoms and the KeySets they are contained in
+   * \return specific fragment map
+   */
+  atomkeyset_t getCandidatesSpecificKeySetMap(
+      const candidates_t &_candidates,
+      const atomkeyset_t &_atomkeyset) const;
+
+  /** For a given set of candidates atoms in \a _candidates and a \a _keyset
+   * we combine each fragment from either atom and place it into internal
+   * Graph.
+   *
+   * \param _MaxOrder maximum order
+   * \param _candidates all atoms neighboring the current out outside of its molecule
+   * \param _fragmentmap all keysets related to this atom
+   * \param _keyset current keyset (used as base for creating inter-fragments)
+   * \param _InterFragments container for all created inter-fragments
+   * \param _counter counts added fragments
+   */
+  void combineFragments(
+      const candidates_t &_candidates,
+      atomkeyset_t &_fragmentmap,
+      const KeySet &_keyset,
+      Graph &_InterFragments,
+      int &_counter);
 
 private:
