Index: src/World.cpp
===================================================================
--- src/World.cpp	(revision ee86a01bf2b6b9841d0ca5f11c1b068aec775fd6)
+++ src/World.cpp	(revision dc11c9885b5f04eecfb275bda7687c5c1da10440)
@@ -234,8 +234,8 @@
     atomIdPool_t::iterator iter=atomIdPool.begin();
     atomId_t id = iter->first;
-    pair<atomId_t,atomId_t> newRange = make_pair(id+1,iter->second);
+    range<atomId_t> newRange = makeRange(id+1,iter->last);
     // we wont use this iterator anymore, so we don't care about invalidating
     atomIdPool.erase(iter);
-    if(newRange.first<newRange.second){
+    if(newRange.first<newRange.last){
       atomIdPool.insert(newRange);
     }
@@ -247,5 +247,5 @@
 
 void World::releaseAtomId(atomId_t id){
-  atomIdPool.insert(make_pair(id,id+1));
+  atomIdPool.insert(makeRange(id,id+1));
   defragAtomIdPool();
 }
@@ -253,6 +253,6 @@
 bool World::reserveAtomId(atomId_t id){
   if(id>=currAtomId ){
-    pair<atomId_t,atomId_t> newRange = make_pair(currAtomId,id);
-    if(newRange.first<newRange.second){
+    range<atomId_t> newRange = makeRange(currAtomId,id);
+    if(newRange.first<newRange.last){
       atomIdPool.insert(newRange);
     }
@@ -263,21 +263,21 @@
   // look for a range that matches the request
   for(atomIdPool_t::iterator iter=atomIdPool.begin();iter!=atomIdPool.end();++iter){
-    if(iter->first>id){
-      // we have coverd all available ranges... nothing to be found here
+    if(iter->isBefore(id)){
+      // we have covered all available ranges... nothing to be found here
       break;
     }
     // no need to check first, since it has to be <=id, since otherwise we would have broken out
-    if(iter->second > id){
+    if(!iter->isBeyond(id)){
       // we found a matching range... get the id from this range
 
       // split up this range at the point of id
-      pair<atomId_t,atomId_t> bottomRange = make_pair(iter->first,id);
-      pair<atomId_t,atomId_t> topRange = make_pair(id+1,iter->second);
+      range<atomId_t> bottomRange = makeRange(iter->first,id);
+      range<atomId_t> topRange = makeRange(id+1,iter->last);
       // remove this range
       atomIdPool.erase(iter);
-      if(bottomRange.first<bottomRange.second){
+      if(bottomRange.first<bottomRange.last){
         atomIdPool.insert(bottomRange);
       }
-      if(topRange.first<topRange.second){
+      if(topRange.first<topRange.last){
         atomIdPool.insert(topRange);
       }
@@ -301,7 +301,7 @@
     atomIdPool_t::iterator next = iter;
     next++;
-    if(next!=atomIdPool.end() && (next->first==iter->second)){
+    if(next!=atomIdPool.end() && (next->first==iter->last)){
       // merge the two ranges
-      pair<atomId_t,atomId_t> newRange = make_pair(iter->first,next->second);
+      range<atomId_t> newRange = makeRange(iter->first,next->last);
       atomIdPool.erase(iter);
       atomIdPool.erase(next);
@@ -317,5 +317,5 @@
     atomIdPool_t::iterator iter = atomIdPool.end();
     iter--;
-    if(iter->second==currAtomId){
+    if(iter->last==currAtomId){
       currAtomId=iter->first;
       atomIdPool.erase(iter);
@@ -333,8 +333,8 @@
     moleculeIdPool_t::iterator iter=moleculeIdPool.begin();
     moleculeId_t id = iter->first;
-    pair<moleculeId_t,moleculeId_t> newRange = make_pair(id+1,iter->second);
+    range<moleculeId_t> newRange = makeRange(id+1,iter->last);
     // we wont use this iterator anymore, so we don't care about invalidating
     moleculeIdPool.erase(iter);
-    if(newRange.first<newRange.second){
+    if(newRange.first<newRange.last){
       moleculeIdPool.insert(newRange);
     }
@@ -346,5 +346,5 @@
 
 void World::releaseMoleculeId(moleculeId_t id){
-  moleculeIdPool.insert(make_pair(id,id+1));
+  moleculeIdPool.insert(makeRange(id,id+1));
   defragMoleculeIdPool();
 }
@@ -352,6 +352,6 @@
 bool World::reserveMoleculeId(moleculeId_t id){
   if(id>=currMoleculeId ){
-    pair<moleculeId_t,moleculeId_t> newRange = make_pair(currMoleculeId,id);
-    if(newRange.first<newRange.second){
+    range<moleculeId_t> newRange = makeRange(currMoleculeId,id);
+    if(newRange.first<newRange.last){
       moleculeIdPool.insert(newRange);
     }
@@ -362,21 +362,21 @@
   // look for a range that matches the request
   for(moleculeIdPool_t::iterator iter=moleculeIdPool.begin();iter!=moleculeIdPool.end();++iter){
-    if(iter->first>id){
+    if(iter->isBefore(id)){
       // we have coverd all available ranges... nothing to be found here
       break;
     }
     // no need to check first, since it has to be <=id, since otherwise we would have broken out
-    if(iter->second > id){
+    if(!iter->isBeyond(id)){
       // we found a matching range... get the id from this range
 
       // split up this range at the point of id
-      pair<moleculeId_t,moleculeId_t> bottomRange = make_pair(iter->first,id);
-      pair<moleculeId_t,moleculeId_t> topRange = make_pair(id+1,iter->second);
+      range<moleculeId_t> bottomRange = makeRange(iter->first,id);
+      range<moleculeId_t> topRange = makeRange(id+1,iter->last);
       // remove this range
       moleculeIdPool.erase(iter);
-      if(bottomRange.first<bottomRange.second){
+      if(bottomRange.first<bottomRange.last){
         moleculeIdPool.insert(bottomRange);
       }
-      if(topRange.first<topRange.second){
+      if(topRange.first<topRange.last){
         moleculeIdPool.insert(topRange);
       }
@@ -400,7 +400,7 @@
     moleculeIdPool_t::iterator next = iter;
     next++;
-    if(next!=moleculeIdPool.end() && (next->first==iter->second)){
+    if(next!=moleculeIdPool.end() && (next->first==iter->last)){
       // merge the two ranges
-      pair<moleculeId_t,moleculeId_t> newRange = make_pair(iter->first,next->second);
+      range<moleculeId_t> newRange = makeRange(iter->first,next->last);
       moleculeIdPool.erase(iter);
       moleculeIdPool.erase(next);
@@ -416,5 +416,5 @@
     moleculeIdPool_t::iterator iter = moleculeIdPool.end();
     iter--;
-    if(iter->second==currMoleculeId){
+    if(iter->last==currMoleculeId){
       currMoleculeId=iter->first;
       moleculeIdPool.erase(iter);
Index: src/World.hpp
===================================================================
--- src/World.hpp	(revision ee86a01bf2b6b9841d0ca5f11c1b068aec775fd6)
+++ src/World.hpp	(revision dc11c9885b5f04eecfb275bda7687c5c1da10440)
@@ -24,4 +24,5 @@
 #include "Patterns/Singleton.hpp"
 #include "Patterns/ObservedContainer.hpp"
+#include "Helpers/Range.hpp"
 
 // include config.h
@@ -354,5 +355,5 @@
   AtomSet atoms;
   AtomSet selectedAtoms;
-  typedef std::set<std::pair<atomId_t, atomId_t> > atomIdPool_t;
+  typedef std::set<range<atomId_t> > atomIdPool_t;
   /**
    * stores the pool for all available AtomIds below currAtomId
@@ -367,5 +368,5 @@
   MoleculeSet molecules;
   MoleculeSet selectedMolecules;
-  typedef std::set<std::pair<moleculeId_t, moleculeId_t> > moleculeIdPool_t;
+  typedef std::set<range<atomId_t> > moleculeIdPool_t;
   /**
    * stores the pool for all available AtomIds below currAtomId
