Index: molecuilder/src/Patterns/Singleton.hpp
===================================================================
--- molecuilder/src/Patterns/Singleton.hpp	(revision 4fc41abe90d8b3b72d0fda5a5f13a2aba7e13cc0)
+++ molecuilder/src/Patterns/Singleton.hpp	(revision abab7efcc313685fb8ec0d7d5c08e812529aa5a8)
@@ -87,5 +87,5 @@
 
 private:
-  static boost::mutex instanceLock;
+  static boost::recursive_mutex instanceLock;
   static ptr_t theInstance;
 };
Index: molecuilder/src/Patterns/Singleton_impl.hpp
===================================================================
--- molecuilder/src/Patterns/Singleton_impl.hpp	(revision 4fc41abe90d8b3b72d0fda5a5f13a2aba7e13cc0)
+++ molecuilder/src/Patterns/Singleton_impl.hpp	(revision abab7efcc313685fb8ec0d7d5c08e812529aa5a8)
@@ -10,4 +10,83 @@
 
 #include "Patterns/Singleton.hpp"
+
+/****** Static instance Variables of the template *******/
+
+template <class T,bool _may_create>
+typename Singleton<T,_may_create>::ptr_t Singleton<T,_may_create>::theInstance(0);
+
+template <class T,bool _may_create>
+boost::recursive_mutex Singleton<T,_may_create>::instanceLock;
+
+/****** templates singleton creation and destruction functions ******/
+
+template <class T,bool _may_create>
+T& Singleton<T,_may_create>::getInstance(){
+  // boost supports RAII-Style locking, so we don't need to unlock
+  boost::recursive_mutex::scoped_lock guard(instanceLock);
+  if(!theInstance.get()) {
+    theInstance.reset(creator::make());
+  }
+  return *theInstance;
+}
+
+template <class T,bool _may_create>
+T* Singleton<T,_may_create>::getPointer(){
+  // boost supports RAII-Style locking, so we don't need to unlock
+  boost::recursive_mutex::scoped_lock guard(instanceLock);
+  if(!theInstance.get()) {
+    theInstance.reset(creator::make());
+  }
+  return theInstance.get();
+
+}
+
+template <class T,bool _may_create>
+void Singleton<T,_may_create>::purgeInstance(){
+  // boost supports RAII-Style locking, so we don't need to unlock
+  boost::recursive_mutex::scoped_lock guard(instanceLock);
+  theInstance.reset();
+}
+
+template <class T,bool _may_create>
+T& Singleton<T,_may_create>::resetInstance(){
+  ptr_t oldInstance;
+  {
+    // boost supports RAII-Style locking, so we don't need to unlock
+    boost::recursive_mutex::scoped_lock guard(instanceLock);
+
+    oldInstance = theInstance;
+    theInstance.reset(creator::make());
+    // oldworld does not need protection any more,
+    // since we should have the only reference
+
+    // worldLock handles access to the pointer,
+    // not to the object
+  } // scope-end releases the lock
+
+  // oldInstance goes out of scope at the End of this function. The carried object will then be destroyed by the auto_ptr
+  return *theInstance;
+}
+
+
+template <class T,bool _may_create>
+void Singleton<T,_may_create>::setInstance(T* newInstance){
+  assert(!theInstance.get() && "Trying to set the instance of an already created singleton");
+  boost::recursive_mutex::scoped_lock guard(instanceLock);
+  theInstance.reset(newInstance);
+}
+
+/**
+ * This define allows simple instantiation of the necessary singleton functions
+ * at a chosen place.
+ */
+#define CONSTRUCT_SINGLETON(name) \
+    template name& Singleton< name , name::may_create >::getInstance(); \
+    template name* Singleton< name , name::may_create >::getPointer();  \
+    template void  Singleton< name , name::may_create >::purgeInstance(); \
+    template name& Singleton< name , name::may_create >::resetInstance(); \
+    template void  Singleton< name , name::may_create >::setInstance( name* );
+
+/************ Internal Pointer Wrapper to allow automatic purging *************/
 
 template <class T,bool _may_create>
@@ -51,72 +130,4 @@
 }
 
-template <class T,bool _may_create>
-typename Singleton<T,_may_create>::ptr_t Singleton<T,_may_create>::theInstance(0);
-
-template <class T,bool _may_create>
-boost::mutex Singleton<T,_may_create>::instanceLock;
-
-template <class T,bool _may_create>
-T& Singleton<T,_may_create>::getInstance(){
-  // boost supports RAII-Style locking, so we don't need to unlock
-  boost::mutex::scoped_lock guard(instanceLock);
-  if(!theInstance.get()) {
-    theInstance.reset(creator::make());
-  }
-  return *theInstance;
-}
-
-template <class T,bool _may_create>
-T* Singleton<T,_may_create>::getPointer(){
-  // boost supports RAII-Style locking, so we don't need to unlock
-  boost::mutex::scoped_lock guard(instanceLock);
-  if(!theInstance.get()) {
-    theInstance.reset(creator::make());
-  }
-  return theInstance.get();
-
-}
-
-template <class T,bool _may_create>
-void Singleton<T,_may_create>::purgeInstance(){
-  // boost supports RAII-Style locking, so we don't need to unlock
-  boost::mutex::scoped_lock guard(instanceLock);
-  theInstance.reset();
-}
-
-template <class T,bool _may_create>
-T& Singleton<T,_may_create>::resetInstance(){
-  ptr_t oldInstance;
-  {
-    // boost supports RAII-Style locking, so we don't need to unlock
-    boost::mutex::scoped_lock guard(instanceLock);
-
-    oldInstance = theInstance;
-    theInstance.reset(creator::make());
-    // oldworld does not need protection any more,
-    // since we should have the only reference
-
-    // worldLock handles access to the pointer,
-    // not to the object
-  } // scope-end releases the lock
-
-  // oldInstance goes out of scope at the End of this function. The carried object will then be destroyed by the auto_ptr
-  return *theInstance;
-}
-
-
-template <class T,bool _may_create>
-void Singleton<T,_may_create>::setInstance(T* newInstance){
-  assert(!theInstance.get() && "Trying to set the instance of an already created singleton");
-  boost::mutex::scoped_lock guard(instanceLock);
-  theInstance.reset(newInstance);
-}
-
-#define CONSTRUCT_SINGLETON(name) \
-    template name& Singleton< name , name::may_create >::getInstance(); \
-    template name* Singleton< name , name::may_create >::getPointer();  \
-    template void  Singleton< name , name::may_create >::purgeInstance(); \
-    template name& Singleton< name , name::may_create >::resetInstance(); \
-    template void  Singleton< name , name::may_create >::setInstance( name* );
 
 #endif /* SINGLETON_IMPL_HPP_ */
