Index: src/Fragmentation/AtomFragmentsMap.cpp
===================================================================
--- src/Fragmentation/AtomFragmentsMap.cpp	(revision d45ed9aa66c406a65fe266151e1d655c799f9d6d)
+++ src/Fragmentation/AtomFragmentsMap.cpp	(revision bd6e5cea786e2eef1815fd25b1b4d870619ea0bb)
@@ -54,13 +54,11 @@
     const KeySet &keyset = keysetiter->first;
     LOG(2, "DEBUG: Current keyset is " << keyset);
-    const AtomIdSet atoms(keyset);
-    const size_t atoms_size = atoms.getAtomIds().size();
-    if ((atoms_size > _MaxOrder) || (atoms_size == 0))
+    if ((keyset.size() > _MaxOrder) || (keyset.empty()))
       continue;
-    for (AtomIdSet::const_iterator atomiter = atoms.begin();
-        atomiter != atoms.end(); ++atomiter) {
+    for (KeySet::const_iterator keyiter = keyset.begin();
+        keyiter != keyset.end(); ++keyiter) {
       // either create new list ...
       std::pair<AtomFragmentsMap_t::iterator, bool> inserter =
-          atommap.insert( std::make_pair(*atomiter, keysets_t(1, &keyset) ));
+          atommap.insert( std::make_pair(*keyiter, keysets_t(1, keyset) ));
       // ... or push to end
       if (inserter.second) {
@@ -68,5 +66,5 @@
       } else {
         LOG(3, "DEBUG: Added keyset to present entry.");
-        inserter.first->second.push_back(&keyset);
+        inserter.first->second.push_back(keyset);
       }
     }
Index: src/Fragmentation/AtomFragmentsMap.hpp
===================================================================
--- src/Fragmentation/AtomFragmentsMap.hpp	(revision d45ed9aa66c406a65fe266151e1d655c799f9d6d)
+++ src/Fragmentation/AtomFragmentsMap.hpp	(revision bd6e5cea786e2eef1815fd25b1b4d870619ea0bb)
@@ -18,5 +18,6 @@
 #include <map>
 
-class atom;
+#include "types.hpp"
+
 class KeySet;
 class Graph;
@@ -33,7 +34,7 @@
       size_t _MaxOrder);
 
-  typedef std::list<const KeySet *> keysets_t;
+  typedef std::list<KeySet> keysets_t;
   //!> typedef for the internal map
-  typedef std::map<const atom *, keysets_t> AtomFragmentsMap_t;
+  typedef std::map<atomId_t, keysets_t> AtomFragmentsMap_t;
 
   const AtomFragmentsMap_t& getMap() const
Index: src/Fragmentation/Interfragmenter.cpp
===================================================================
--- src/Fragmentation/Interfragmenter.cpp	(revision d45ed9aa66c406a65fe266151e1d655c799f9d6d)
+++ src/Fragmentation/Interfragmenter.cpp	(revision bd6e5cea786e2eef1815fd25b1b4d870619ea0bb)
@@ -107,10 +107,10 @@
   for (candidates_t::const_iterator candidateiter = _candidates.begin();
       candidateiter != _candidates.end(); ++candidateiter) {
-    const atom * _atom = *candidateiter;
-    atomkeyset_t::const_iterator iter = _atomkeyset.find(_atom);
+    const atomId_t atomid = (*candidateiter)->getId();
+    atomkeyset_t::const_iterator iter = _atomkeyset.find(atomid);
     ASSERT( iter != _atomkeyset.end(),
         "Interfragmenter::getAtomSpecificKeySetMap() - could not find atom "
-        +toString(_atom->getId())+" in lookup.");
-    fragmentmap.insert( std::make_pair( _atom, iter->second) );
+        +toString(atomid)+" in lookup.");
+    fragmentmap.insert( std::make_pair( atomid, iter->second) );
   }
   LOG(4, "DEBUG: Copied part of lookup map contains " << fragmentmap.size() << " keys.");
@@ -122,5 +122,5 @@
     const size_t _MaxOrder,
     const candidates_t &_candidates,
-    atomkeyset_t &_fragmentmap,
+    const atomkeyset_t &_fragmentmap,
     const KeySet &_keyset,
     Graph &_InterFragments,
@@ -131,9 +131,10 @@
     const atom *_atom = *candidateiter;
     LOG(3, "DEBUG: Current candidate is " << *_atom << ".");
-    atomkeyset_t::iterator finditer = _fragmentmap.find(_atom);
+    atomkeyset_t::const_iterator finditer = _fragmentmap.find(_atom->getId());
     ASSERT( finditer != _fragmentmap.end(),
         "Interfragmenter::combineFragments() - could not find atom "
         +toString(_atom->getId())+" in fragment specific lookup.");
-    keysets_t &othersets = finditer->second;
+    // copy set to allow erase
+    keysets_t othersets(finditer->second);
     ASSERT( !othersets.empty(),
         "Interfragmenter::combineFragments() - keysets to "+toString(_atom->getId())+
@@ -141,5 +142,5 @@
     keysets_t::iterator otheriter = othersets.begin();
     while (otheriter != othersets.end()) {
-      const KeySet &otherset = **otheriter;
+      const KeySet &otherset = *otheriter;
       LOG(3, "DEBUG: Current keyset is " << otherset << ".");
       // only add them one way round and not the other
Index: src/Fragmentation/Interfragmenter.hpp
===================================================================
--- src/Fragmentation/Interfragmenter.hpp	(revision d45ed9aa66c406a65fe266151e1d655c799f9d6d)
+++ src/Fragmentation/Interfragmenter.hpp	(revision bd6e5cea786e2eef1815fd25b1b4d870619ea0bb)
@@ -114,5 +114,5 @@
       const size_t _MaxOrder,
       const candidates_t &_candidates,
-      atomkeyset_t &_fragmentmap,
+      const atomkeyset_t &_fragmentmap,
       const KeySet &_keyset,
       Graph &_InterFragments,
