Index: molecuilder/src/Actions/small_actions.cpp
===================================================================
--- molecuilder/src/Actions/small_actions.cpp	(revision 4c60efc9daef2d68869fae039baec156ac6999d3)
+++ molecuilder/src/Actions/small_actions.cpp	(revision 4fc41abe90d8b3b72d0fda5a5f13a2aba7e13cc0)
@@ -27,5 +27,5 @@
   string filename;
   molecule *mol = NULL;
-  Dialog *dialog = UIFactory::get()->makeDialog();
+  Dialog *dialog = UIFactory::getInstance().makeDialog();
 
   dialog->queryMolecule("Enter index of molecule: ",&mol,molecules);
Index: molecuilder/src/Legacy/oldmenu.cpp
===================================================================
--- molecuilder/src/Legacy/oldmenu.cpp	(revision 4c60efc9daef2d68869fae039baec156ac6999d3)
+++ molecuilder/src/Legacy/oldmenu.cpp	(revision 4fc41abe90d8b3b72d0fda5a5f13a2aba7e13cc0)
@@ -912,5 +912,5 @@
 void oldmenu::SimpleAddMolecules(MoleculeListClass *molecules) {
   molecule *srcmol = NULL, *destmol = NULL;
-  Dialog *dialog = UIFactory::get()->makeDialog();
+  Dialog *dialog = UIFactory::getInstance().makeDialog();
   dialog->queryMolecule("Enter index of destination molecule: ",&destmol, molecules);
   dialog->queryMolecule("Enter index of source molecule to add from: ",&srcmol, molecules);
@@ -926,5 +926,5 @@
 void oldmenu::embeddMolecules(MoleculeListClass *molecules) {
   molecule *srcmol = NULL, *destmol = NULL;
-  Dialog *dialog = UIFactory::get()->makeDialog();
+  Dialog *dialog = UIFactory::getInstance().makeDialog();
   dialog->queryMolecule("Enter index of matrix molecule (the variable one): ",&srcmol,molecules);
   dialog->queryMolecule("Enter index of molecule to merge into (the fixed one): ",&destmol,molecules);
Index: molecuilder/src/Patterns/Singleton.hpp
===================================================================
--- molecuilder/src/Patterns/Singleton.hpp	(revision 4c60efc9daef2d68869fae039baec156ac6999d3)
+++ molecuilder/src/Patterns/Singleton.hpp	(revision 4fc41abe90d8b3b72d0fda5a5f13a2aba7e13cc0)
@@ -9,5 +9,6 @@
 #define SINGLETON_HPP_
 
-#include <memory>
+#include <cassert>
+#include <boost/thread.hpp>
 
 #include "defs.hpp"
Index: molecuilder/src/Patterns/Singleton_impl.hpp
===================================================================
--- molecuilder/src/Patterns/Singleton_impl.hpp	(revision 4c60efc9daef2d68869fae039baec156ac6999d3)
+++ molecuilder/src/Patterns/Singleton_impl.hpp	(revision 4fc41abe90d8b3b72d0fda5a5f13a2aba7e13cc0)
@@ -9,5 +9,5 @@
 #define SINGLETON_IMPL_HPP_
 
-#include <cassert>
+#include "Patterns/Singleton.hpp"
 
 template <class T,bool _may_create>
Index: molecuilder/src/UIElements/UIFactory.cpp
===================================================================
--- molecuilder/src/UIElements/UIFactory.cpp	(revision 4c60efc9daef2d68869fae039baec156ac6999d3)
+++ molecuilder/src/UIElements/UIFactory.cpp	(revision 4fc41abe90d8b3b72d0fda5a5f13a2aba7e13cc0)
@@ -8,10 +8,9 @@
 
 #include <cassert>
+#include "Patterns/Singleton_impl.hpp"
 #include "UIElements/UIFactory.hpp"
 
 // all factories that can be used:
 #include "UIElements/TextUIFactory.hpp"
-
-UIFactory *UIFactory::theFactory = 0;
 
 UIFactory::UIFactory()
@@ -27,8 +26,7 @@
 
 void UIFactory::makeUserInterface(InterfaceTypes type) {
-  assert(theFactory == 0 && "makeUserInterface should only be called once");
   switch(type) {
     case Text :
-      theFactory = new TextUIFactory();
+      setInstance(new TextUIFactory());
       break;
 
@@ -39,14 +37,3 @@
 }
 
-UIFactory* UIFactory::get(){
-  assert(theFactory != 0 && "No UserInterface created prior to factory access");
-  return theFactory;
-}
-
-
-void UIFactory::purgeInstance(){
-  if(theFactory) {
-    delete theFactory;
-    theFactory = 0;
-  }
-}
+CONSTRUCT_SINGLETON(UIFactory)
Index: molecuilder/src/UIElements/UIFactory.hpp
===================================================================
--- molecuilder/src/UIElements/UIFactory.hpp	(revision 4c60efc9daef2d68869fae039baec156ac6999d3)
+++ molecuilder/src/UIElements/UIFactory.hpp	(revision 4fc41abe90d8b3b72d0fda5a5f13a2aba7e13cc0)
@@ -17,4 +17,7 @@
 
 struct menuPopulaters;
+
+#include "Patterns/Singleton.hpp"
+
 /**
  * Abstract Factory to create any kind of User interface object needed by the programm.
@@ -24,5 +27,5 @@
  * UIs can be handled in a concise abstract way.
  */
-class UIFactory
+class UIFactory : public Singleton<UIFactory,false>
 {
 
@@ -45,8 +48,4 @@
   UIFactory();
 
-// singleton stuff
-private:
-  static UIFactory *theFactory;
-
 public:
   /**
@@ -55,15 +54,4 @@
   static void makeUserInterface(InterfaceTypes type);
 
-  /**
-   * get the previously created factory
-   */
-  static UIFactory* get();
-
-  /**
-   * Destroy the created factory.
-   *
-   * Make sure that all UIElements that were created by the factory are destroyed before calling this method.
-   */
-  static void purgeInstance();
 };
 
Index: molecuilder/src/builder.cpp
===================================================================
--- molecuilder/src/builder.cpp	(revision 4c60efc9daef2d68869fae039baec156ac6999d3)
+++ molecuilder/src/builder.cpp	(revision 4fc41abe90d8b3b72d0fda5a5f13a2aba7e13cc0)
@@ -2225,5 +2225,5 @@
 
       UIFactory::makeUserInterface(UIFactory::Text);
-      MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName);
+      MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName);
       mainWindow->display();
       delete mainWindow;
