Index: src/Fragmentation/Exporters/ExportGraph_ToFiles.cpp
===================================================================
--- src/Fragmentation/Exporters/ExportGraph_ToFiles.cpp	(revision ca8bea22ad6c12313c02f7a53946becdc3eff35a)
+++ src/Fragmentation/Exporters/ExportGraph_ToFiles.cpp	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
@@ -44,4 +44,5 @@
 #include "Fragmentation/Graph.hpp"
 #include "Fragmentation/KeySet.hpp"
+#include "Fragmentation/SortIndex.hpp"
 #include "Graph/ListOfLocalAtoms.hpp"
 #include "molecule.hpp"
@@ -88,8 +89,4 @@
 
   // ===== 9. Save fragments' configuration and keyset files et al to disk ===
-  // create the SortIndex from BFS labels to order in the config file
-  std::map<atomId_t, int> SortIndex;
-  CreateMappingLabelsToConfigSequence(SortIndex);
-
   LOG(1, "Writing " << BondFragments.ListOfMolecules.size() << " possible bond fragmentation configs");
   bool write_status = true;
@@ -109,5 +106,8 @@
 
   // store force index reference file
-  BondFragments.StoreForcesFile(prefix, SortIndex);
+  {
+    SortIndex_t SortIndex(mol);
+    BondFragments.StoreForcesFile(prefix, SortIndex);
+  }
 
   // store keysets file
@@ -254,27 +254,2 @@
 }
 
-/** Create a SortIndex to map from atomic labels to the sequence in which the atoms are given in the config file.
- * \param &SortIndex Mapping array of size molecule::AtomCount
- * \return true - success, false - failure of SortIndex alloc
- */
-bool ExportGraph_ToFiles::CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex)
-{
-  if (!SortIndex.empty()) {
-    LOG(1, "SortIndex has " << SortIndex.size() << " entries and is not empty as expected.");
-    return false;
-  }
-
-  int AtomNo = 0;
-  for(molecule::const_iterator iter=mol->begin();iter!=mol->end();++iter){
-    const int id = (*iter)->getNr();
-#ifndef NDEBUG
-      std::pair<std::map<atomId_t, int>::const_iterator, bool> inserter =
-#endif
-    SortIndex.insert( std::make_pair(id, AtomNo++) );
-    ASSERT( inserter.second ,
-        "ExportGraph_ToFiles::CreateMappingLabelsToConfigSequence() - same SortIndex set twice.");
-  }
-
-  return true;
-}
-
Index: src/Fragmentation/Exporters/ExportGraph_ToFiles.hpp
===================================================================
--- src/Fragmentation/Exporters/ExportGraph_ToFiles.hpp	(revision ca8bea22ad6c12313c02f7a53946becdc3eff35a)
+++ src/Fragmentation/Exporters/ExportGraph_ToFiles.hpp	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
@@ -48,6 +48,4 @@
   int StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList);
   void CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem);
-  bool CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex);
-
 
 private:
Index: src/Fragmentation/Graph.cpp
===================================================================
--- src/Fragmentation/Graph.cpp	(revision ca8bea22ad6c12313c02f7a53946becdc3eff35a)
+++ src/Fragmentation/Graph.cpp	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
@@ -156,5 +156,4 @@
   }
   output.close();
-  output.clear();
 
   return status;
Index: src/Fragmentation/Makefile.am
===================================================================
--- src/Fragmentation/Makefile.am	(revision ca8bea22ad6c12313c02f7a53946becdc3eff35a)
+++ src/Fragmentation/Makefile.am	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
@@ -18,4 +18,5 @@
 	Fragmentation/MatrixContainer.cpp \
 	Fragmentation/PowerSetGenerator.cpp \
+	Fragmentation/SortIndex.cpp \
 	Fragmentation/UniqueFragments.cpp
 
@@ -42,4 +43,5 @@
 	Fragmentation/MoleculeMask.hpp \
 	Fragmentation/PowerSetGenerator.hpp \
+	Fragmentation/SortIndex.hpp \
 	Fragmentation/UniqueFragments.hpp
 
Index: src/Fragmentation/SortIndex.cpp
===================================================================
--- src/Fragmentation/SortIndex.cpp	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
+++ src/Fragmentation/SortIndex.cpp	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
@@ -0,0 +1,74 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+/*
+ * SortIndex.cpp
+ *
+ *  Created on: Sep 20, 2012
+ *      Author: heber
+ */
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "Fragmentation/SortIndex.hpp"
+
+#include "CodePatterns/Assert.hpp"
+
+#include "molecule.hpp"
+
+SortIndex_t::SortIndex_t()
+{}
+
+/** Constructor for SortIndex from the internal numbering in a molecule.
+ *
+ * \param *mol molecule to place in the internal index
+ */
+SortIndex_t::SortIndex_t(const molecule *mol)
+{
+  int AtomNo = 0;
+  for(molecule::const_iterator iter=mol->begin();iter!=mol->end();++iter){
+#ifndef NDEBUG
+    std::pair<index_t::iterator, bool> inserter =
+#endif
+        index.insert( std::make_pair((*iter)->getNr(), AtomNo) );
+    ASSERT( inserter.second,
+        "SortIndex_t::SortIndex_t() - index "+toString((*iter)->getNr())+" already present.");
+    ++AtomNo;
+  }
+}
+
+
+int SortIndex_t::find(atomId_t id) const
+{
+  index_t::const_iterator iter = index.find(id);
+  if (iter == index.end())
+    return -1;
+  else
+    return iter->second;
+}
Index: src/Fragmentation/SortIndex.hpp
===================================================================
--- src/Fragmentation/SortIndex.hpp	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
+++ src/Fragmentation/SortIndex.hpp	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
@@ -0,0 +1,40 @@
+/*
+ * SortIndex.hpp
+ *
+ *  Created on: Sep 20, 2012
+ *      Author: heber
+ */
+
+#ifndef SORTINDEX_HPP_
+#define SORTINDEX_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <map>
+
+#include "types.hpp"
+
+class molecule;
+
+/** This is just a wrapper class meant for refactoring. It emulates a map.
+ *
+ */
+class SortIndex_t
+{
+public:
+  SortIndex_t();
+  SortIndex_t(const molecule *mol);
+
+  int find(atomId_t id) const;
+
+private:
+  typedef std::map<atomId_t, int> index_t;
+  index_t index;
+};
+
+
+#endif /* SORTINDEX_HPP_ */
Index: src/MoleculeListClass.hpp
===================================================================
--- src/MoleculeListClass.hpp	(revision ca8bea22ad6c12313c02f7a53946becdc3eff35a)
+++ src/MoleculeListClass.hpp	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
@@ -27,4 +27,5 @@
 class molecule;
 class periodentafel;
+class SortIndex_t;
 class World;
 
@@ -45,5 +46,5 @@
 
   bool AddHydrogenCorrection(std::string &path);
-  bool StoreForcesFile(std::string &path, const std::map<atomId_t, int> &SortIndex);
+  bool StoreForcesFile(std::string &path, const SortIndex_t &SortIndex);
   void insert(molecule *mol);
   void erase(molecule *mol);
Index: src/moleculelist.cpp
===================================================================
--- src/moleculelist.cpp	(revision ca8bea22ad6c12313c02f7a53946becdc3eff35a)
+++ src/moleculelist.cpp	(revision dcbb5dac817f661e01dae1a9436a1ec9bb379493)
@@ -51,4 +51,5 @@
 #include "Fragmentation/Graph.hpp"
 #include "Fragmentation/KeySet.hpp"
+#include "Fragmentation/SortIndex.hpp"
 #include "Graph/BondGraph.hpp"
 #include "Helpers/helpers.hpp"
@@ -492,5 +493,5 @@
  * \return true - file written successfully, false - writing failed
  */
-bool MoleculeListClass::StoreForcesFile(std::string &path, const std::map<atomId_t, int> &SortIndex)
+bool MoleculeListClass::StoreForcesFile(std::string &path, const SortIndex_t &SortIndex)
 {
   bool status = true;
@@ -512,9 +513,5 @@
               if (((*atomIter)->GetTrueFather() != NULL) && ((*atomIter)->GetTrueFather() != (*atomIter))) {// if there is a rea
                 const atomId_t fatherid = (*atomIter)->GetTrueFather()->getNr();
-                const std::map<atomId_t, int>::const_iterator iter = SortIndex.find(fatherid);
-                if( iter != SortIndex.end())
-                  ForcesFile << iter->second << "\t";
-                else
-                  ForcesFile << "-1\t";
+                ForcesFile << SortIndex.find(fatherid) << "\t";
               } else
                 // otherwise a -1 to indicate an added saturation hydrogen
