Index: src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp
===================================================================
--- src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp	(revision 7c7c4adf3a00ea2410433016fef5f193bab8b957)
+++ src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp	(revision 16bd376fd9b011d5e40fc688f849c8418b4ad1f9)
@@ -86,5 +86,7 @@
   owner(NULL)
 {
-  initObservedValues(_id);
+  boost::function<void()> subjectKilled =
+      boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this);
+  initObservedValues(ObservedValues, _id, atomref, subjectKilled);
 
   setObjectId(_id);
@@ -136,5 +138,5 @@
 {
   deactivateObserver();
-  destroyObservedValues();
+  destroyObservedValues(ObservedValues);
 }
 
@@ -259,12 +261,13 @@
 }
 
-atomId_t GLMoleculeObject_atom::updateIndex() const
+atomId_t GLMoleculeObject_atom::updateIndex()
 {
   return const_cast<const World &>(World::getInstance()).lastChangedAtomId();
 }
 
-Vector GLMoleculeObject_atom::updatePosition() const
-{
-  const atom * const _atom = getAtom(getAtomIndex());
+Vector GLMoleculeObject_atom::updatePosition(
+    const boost::function<const atomId_t ()> &_getAtomIndex)
+{
+  const atom * const _atom = getAtomConst(_getAtomIndex());
   if (_atom != NULL) {
     return _atom->getPosition();
@@ -274,7 +277,8 @@
 }
 
-atomicNumber_t GLMoleculeObject_atom::updateElement() const
-{
-  const atom * const _atom = getAtom(getAtomIndex());
+atomicNumber_t GLMoleculeObject_atom::updateElement(
+    const boost::function<const atomId_t ()> &_getAtomIndex)
+{
+  const atom * const _atom = getAtomConst(_getAtomIndex());
   if (_atom != NULL) {
     return _atom->getElementNo();
@@ -284,10 +288,11 @@
 }
 
-GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::updateBonds() const
+GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::updateBonds(
+    const boost::function<const atomId_t ()> &_getAtomIndex)
 {
   ListOfBonds_t ListOfBonds;
-  const atom * const _atom = getAtom(getAtomIndex());
+  const atom * const _atom = getAtomConst(_getAtomIndex());
   if (_atom != NULL) {
-    // make sure position is up-to-date
+    // make sure bonds is up-to-date
     const BondList ListBonds = _atom->getListOfBonds();
     for (BondList::const_iterator iter = ListBonds.begin();
@@ -298,5 +303,5 @@
           (*iter)->rightatom->getId()) );
   } else {
-    ELOG(2, "Atom with id "+toString(getAtomIndex())+" is already gone.");
+    ELOG(2, "Atom with id "+toString(_getAtomIndex())+" is already gone.");
   }
   return ListOfBonds;
@@ -351,46 +356,78 @@
 }
 
-void GLMoleculeObject_atom::initObservedValues(const atomId_t _id)
-{
-  // fill ObservedValues
-  boost::function<void()> subjectKilled =
-      boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this);
-  ObservedValues[AtomIndex] = new ObservedValue_wCallback<atomId_t>(
-      atomref,
-      boost::bind(&GLMoleculeObject_atom::updateIndex, this),
-      "AtomIndex_"+toString(_id),
-      _id,
-      AtomIndexChannels,
-      subjectKilled);
-  ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector>(
-      atomref,
-      boost::bind(&GLMoleculeObject_atom::updatePosition, this),
+void GLMoleculeObject_atom::initObservedValues(
+    std::vector<boost::any> &_ObservedValues,
+    const atomId_t _id,
+    const atom * const _atomref,
+    const boost::function<void()> &_subjectKilled)
+{
+  /* This is an old note from when the code was still part of cstor's initializer body.
+   * TODO: Probably does not apply anymore but has not yet been tested.
+   *
+   * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
+   * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
+   * the class has not been fully constructed yet. "This" itself seems to be working fine.
+   */
+
+  ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
+      "GLMoleculeObject_atom::initObservedValues() - given ObservedValues has not correct size.");
+
+  // fill ObservedValues: index first
+  const boost::function<atomId_t ()> AtomIndexUpdater(
+      boost::bind(&GLMoleculeObject_atom::updateIndex));
+
+  ObservedValue_wCallback<atomId_t> * const IndexObservable =
+      new ObservedValue_wCallback<atomId_t>(
+          _atomref,
+          boost::bind(&GLMoleculeObject_atom::updateIndex),
+          "AtomIndex_"+toString(_id),
+          _id,
+          AtomIndexChannels,
+          _subjectKilled);
+  _ObservedValues[AtomIndex] = IndexObservable;
+
+  const boost::function<const atomId_t ()> AtomIndexGetter =
+      boost::bind(&ObservedValue_wCallback<atomId_t>::get,
+          IndexObservable);
+
+  // fill ObservedValues: then all the other that need index
+  const boost::function<Vector ()> AtomPositionUpdater(
+      boost::bind(&GLMoleculeObject_atom::updatePosition, AtomIndexGetter));
+  const boost::function<atomicNumber_t ()> AtomElementUpdater(
+      boost::bind(&GLMoleculeObject_atom::updateElement, AtomIndexGetter));
+  const boost::function<ListOfBonds_t ()> AtomBondsUpdater(
+      boost::bind(&GLMoleculeObject_atom::updateBonds, AtomIndexGetter));
+
+  _ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector>(
+      _atomref,
+      AtomPositionUpdater,
       "AtomPosition_"+toString(_id),
-      updatePosition(),
+      AtomPositionUpdater(),
       AtomPositionChannels,
-      subjectKilled);
-  ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t>(
-      atomref,
-      boost::bind(&GLMoleculeObject_atom::updateElement, this),
+      _subjectKilled);
+  _ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t>(
+      _atomref,
+      AtomElementUpdater,
       "AtomElement"+toString(_id),
-      updateElement(),
+      AtomElementUpdater(),
       AtomElementChannels,
-      subjectKilled);
-  ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t>(
-      atomref,
-      boost::bind(&GLMoleculeObject_atom::updateBonds, this),
+      _subjectKilled);
+  _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t>(
+      _atomref,
+      AtomBondsUpdater,
       "AtomBonds_"+toString(_id),
-      updateBonds(),
+      AtomBondsUpdater(),
       AtomBondsChannels,
-      subjectKilled);
-}
-
-void GLMoleculeObject_atom::destroyObservedValues()
-{
-  delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex]);
-  delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[AtomPosition]);
-  delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[AtomElement]);
-  delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(ObservedValues[AtomBonds]);
-  ObservedValues.clear();
+      _subjectKilled);
+}
+
+void GLMoleculeObject_atom::destroyObservedValues(
+    std::vector<boost::any> &_ObservedValues)
+{
+  delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[AtomIndex]);
+  delete boost::any_cast<ObservedValue_wCallback<Vector> *>(_ObservedValues[AtomPosition]);
+  delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(_ObservedValues[AtomElement]);
+  delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(_ObservedValues[AtomBonds]);
+  _ObservedValues.clear();
 }
 
