Index: src/Patterns/Cacheable.hpp
===================================================================
--- src/Patterns/Cacheable.hpp	(revision ea71760f1257d93e6396b87b269d71544d16a690)
+++ src/Patterns/Cacheable.hpp	(revision e0b6fd7a16e107779197cef07ad3b711cc457e33)
@@ -11,4 +11,8 @@
 #include "Patterns/Observer.hpp"
 #include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
+#include <iostream>
+
+#include "Helpers/Assert.hpp"
 
 #ifndef NO_CACHING
@@ -17,4 +21,106 @@
   class Cacheable : public Observer
   {
+    // we define the states of the cacheable so we can do very fast state-checks
+    class State{
+    public:
+      State(Cacheable *_owner) :
+        owner(_owner),
+        busy(false)
+        {}
+      virtual T& getValue()=0;
+      virtual void invalidate()=0;
+      virtual bool isValid()=0;
+      virtual void enter()=0;
+      bool isBusy(){
+        return busy;
+      }
+    protected:
+      bool busy;
+      Cacheable *owner;
+    };
+
+    class InvalidState : public State{
+    public:
+      InvalidState(Cacheable *_owner):
+        State(_owner)
+        {}
+
+      virtual T& getValue(){
+        // set the state to valid
+        State::owner->switchState(State::owner->validState);
+        // get the value from the now valid state
+        return State::owner->state->getValue();
+      }
+
+      virtual void invalidate(){
+        // nothing to do on this message
+      }
+
+      virtual bool isValid(){
+        return false;
+      }
+
+      virtual void enter(){
+        // nothing to do when entering this
+      }
+    };
+
+    class ValidState : public State{
+    public:
+      ValidState(Cacheable *_owner) :
+        State(_owner)
+        {}
+
+      virtual T& getValue(){
+        return content;
+      }
+
+      virtual void invalidate(){
+        State::owner->switchState(State::owner->invalidState);
+      }
+
+      virtual bool isValid(){
+        return true;
+      }
+
+      virtual void enter(){
+        State::busy= true;
+        // as soon as we enter the valid state we recalculate
+        content = State::owner->recalcMethod();
+        State::busy = false;
+      }
+    private:
+      T content;
+    };
+
+    class DestroyedState : public State {
+    public:
+      DestroyedState(Cacheable *_owner) :
+        State(_owner)
+        {}
+
+      virtual T& getValue(){
+        ASSERT(0,"Cannot get a value from a Cacheable after it's Observable has died");
+        // we have to return a grossly invalid reference, because no value can be produced anymore
+        return *(static_cast<T*>(0));
+      }
+
+      virtual void invalidate(){
+        ASSERT(0,"Cannot invalidate a Cacheable after it's Observable has died");
+      }
+
+      virtual bool isValid(){
+        ASSERT(0,"Cannot check validity of a Cacheable after it's Observable has died");
+        return false;
+      }
+
+      virtual void enter(){
+        // nothing to do when entering this state
+      }
+    };
+
+
+  typedef boost::shared_ptr<State> state_ptr;
+
   public:
     Cacheable(Observable *_owner, boost::function<T()> _recalcMethod);
@@ -28,11 +134,17 @@
     void subjectKilled(Observable *subject);
   private:
-    void checkValid() const;
-
-    mutable T content;
+    void switchState(state_ptr newState);
+
+    mutable state_ptr state;
+    // pre-defined state so we don't have to construct to much
+    state_ptr invalidState;
+    state_ptr validState;
+    // destroyed state is not predefined, because we rarely enter that state and never leave
+
     Observable *owner;
-    mutable bool valid;
-    mutable bool canBeUsed;
     boost::function<T()> recalcMethod;
+
+    // de-activated copy constructor
+    Cacheable(const Cacheable&);
   };
 
@@ -41,8 +153,10 @@
   Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod) :
     owner(_owner),
-    valid(false),
-    canBeUsed(true),
     recalcMethod(_recalcMethod)
   {
+    // create all states needed for this object
+    invalidState = state_ptr(new InvalidState(this));
+    validState = state_ptr(new ValidState(this));
+    state = invalidState;
     // we sign on with the best(=lowest) priority, so cached values are recalculated before
     // anybody else might ask for updated values
@@ -50,8 +164,13 @@
   }
 
+  // de-activated copy constructor
+  template<typename T>
+  Cacheable<T>::Cacheable(const Cacheable&){
+    ASSERT(0,"Cacheables should never be copied");
+  }
+
   template<typename T>
   const T& Cacheable<T>::operator*() const{
-    checkValid();
-    return content;
+    return state->getValue();
   }
 
@@ -64,25 +183,25 @@
   template<typename T>
   const bool Cacheable<T>::isValid() const{
-    return valid;
+    return state->isValid();
   }
 
   template<typename T>
   void Cacheable<T>::update(Observable *subject) {
-    valid = false;
+    state->invalidate();
   }
 
   template<typename T>
   void Cacheable<T>::subjectKilled(Observable *subject) {
-    valid = false;
-    canBeUsed = false;
-  }
-
-  template<typename T>
-  void Cacheable<T>::checkValid() const{
-    assert(canBeUsed && "Cacheable used after owner was deleted");
-    if(!isValid()){
-      content = recalcMethod();
-    }
-  }
+    state_ptr destroyed = state_ptr(new DestroyedState(this));
+    switchState(destroyed);
+  }
+
+  template<typename T>
+  void Cacheable<T>::switchState(state_ptr newState){
+    ASSERT(!state->isBusy(),"LOOP DETECTED: Cacheable state switched while recalculating.\nDid the recalculation trigger the Observable?");
+    state = newState;
+    state->enter();
+  }
+
 #else
   template<typename T>
@@ -125,10 +244,10 @@
   template<typename T>
   void Cacheable<T>::update(Observable *subject) {
-    assert(0 && "Cacheable::update should never be called when caching is disabled");
+    ASSERT(0, "Cacheable::update should never be called when caching is disabled");
   }
 
   template<typename T>
   void Cacheable<T>::subjectKilled(Observable *subject){
-    assert(0 && "Cacheable::subjectKilled should never be called when caching is disabled");
+    ASSERT(0, "Cacheable::subjectKilled should never be called when caching is disabled");
   }
 #endif
Index: src/molecule.cpp
===================================================================
--- src/molecule.cpp	(revision ea71760f1257d93e6396b87b269d71544d16a690)
+++ src/molecule.cpp	(revision e0b6fd7a16e107779197cef07ad3b711cc457e33)
@@ -941,5 +941,5 @@
   int i = 0;
   NoNonHydrogen = 0;
-  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
+  for (molecule::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
     (*iter)->nr = i;   // update number in molecule (for easier referencing in FragmentMolecule lateron)
     if ((*iter)->type->Z != 1) // count non-hydrogen atoms whilst at it
Index: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
===================================================================
--- src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp	(revision ea71760f1257d93e6396b87b269d71544d16a690)
+++ src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp	(revision e0b6fd7a16e107779197cef07ad3b711cc457e33)
@@ -39,5 +39,5 @@
 void AnalysisCorrelationToSurfaceUnitTest::setUp()
 {
-  ASSERT_DO(Assert::Abort);
+  ASSERT_DO(Assert::Throw);
   atom *Walker = NULL;
 
