Index: code/branches/objecthierarchy2/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/LevelManager.cc	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/LevelManager.cc	(revision 2344)
@@ -42,6 +42,4 @@
         assert(singletonRef_s == 0);
         singletonRef_s = this;
-
-        PlayerManager::getInstance(); // ensure existence of PlayerManager
     }
 
Index: code/branches/objecthierarchy2/src/orxonox/Main.cc
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/Main.cc	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/Main.cc	(revision 2344)
@@ -43,4 +43,8 @@
 #include "core/ConfigFileManager.h"
 #include "core/CommandLine.h"
+#include "core/CommandExecutor.h"
+#include "core/Identifier.h"
+#include "core/Core.h"
+#include "core/Language.h"
 
 #include "gamestates/GSRoot.h"
@@ -92,5 +96,6 @@
 
     // create a signal handler (only works for linux)
-    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
+    SignalHandler signalHandler;
+    signalHandler.doCatch(argv[0], "orxonox.log");
 
     // Parse command line arguments
@@ -109,29 +114,44 @@
     ConfigFileManager* configFileManager = new ConfigFileManager();
     configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString());
+    // create the Core settings to configure the output level
+    Language* language = new Language();
+    Core*     core     = new Core();
 
-    // create the gamestates
-    GSRoot root;
-    GSGraphics graphics;
-    GSStandalone standalone;
-    GSServer server;
-    GSClient client;
-    GSDedicated dedicated;
-    GSGUI gui;
-    GSIOConsole ioConsole;
+    // put GameStates in its own scope so we can destroy the identifiers at the end of main().
+    {
+        // create the gamestates
+        GSRoot root;
+        GSGraphics graphics;
+        GSStandalone standalone;
+        GSServer server;
+        GSClient client;
+        GSDedicated dedicated;
+        GSGUI gui;
+        GSIOConsole ioConsole;
 
-    // make the hierarchy
-    root.addChild(&graphics);
-    graphics.addChild(&standalone);
-    graphics.addChild(&server);
-    graphics.addChild(&client);
-    graphics.addChild(&gui);
-    root.addChild(&ioConsole);
-    root.addChild(&dedicated);
+        // make the hierarchy
+        root.addChild(&graphics);
+        graphics.addChild(&standalone);
+        graphics.addChild(&server);
+        graphics.addChild(&client);
+        graphics.addChild(&gui);
+        root.addChild(&ioConsole);
+        root.addChild(&dedicated);
 
-    // Here happens the game
-    root.start();
+        // Here happens the game
+        root.start();
+    }
 
-    // Destroy ConfigFileManager again.
+    // destroy singletons
+    delete core;
+    delete language;
     delete configFileManager;
+
+    // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
+    Identifier::destroyAllIdentifiers();
+    // destroy command line arguments
+    CommandLine::destroyAllArguments();
+    // Also delete external console command that don't belong to an Identifier
+    CommandExecutor::destroyExternalCommands();
 
     return 0;
Index: code/branches/objecthierarchy2/src/orxonox/PlayerManager.cc
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/PlayerManager.cc	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/PlayerManager.cc	(revision 2344)
@@ -38,7 +38,12 @@
 namespace orxonox
 {
+    PlayerManager* PlayerManager::singletonRef_s = 0;
+
     PlayerManager::PlayerManager()
     {
         RegisterRootObject(PlayerManager);
+
+        assert(singletonRef_s == 0);
+        singletonRef_s = this;
 
         this->getConnectedClients();
@@ -47,10 +52,6 @@
     PlayerManager::~PlayerManager()
     {
-    }
-
-    PlayerManager& PlayerManager::getInstance()
-    {
-        static PlayerManager instance;
-        return instance;
+        assert(singletonRef_s);
+        singletonRef_s = 0;
     }
 
Index: code/branches/objecthierarchy2/src/orxonox/PlayerManager.h
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/PlayerManager.h	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/PlayerManager.h	(revision 2344)
@@ -43,5 +43,6 @@
             virtual ~PlayerManager();
 
-            static PlayerManager& getInstance();
+            static PlayerManager& getInstance()
+            { assert(singletonRef_s); return *singletonRef_s; }
 
             PlayerInfo* getClient(unsigned int clientID) const;
@@ -54,4 +55,6 @@
 
             std::map<unsigned int, PlayerInfo*> clients_;
+
+            static PlayerManager* singletonRef_s;
     };
 }
Index: code/branches/objecthierarchy2/src/orxonox/Settings.cc
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/Settings.cc	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/Settings.cc	(revision 2344)
@@ -83,5 +83,5 @@
         }
 
-        LuaBind::getInstance()->setIncludePath(this->dataPath_);
+        LuaBind::getInstance().setIncludePath(this->dataPath_);
     }
 
Index: code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.cc	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.cc	(revision 2344)
@@ -164,5 +164,6 @@
         FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
         functor1->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen"));
+        ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
+        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
     }
 
@@ -170,4 +171,6 @@
     {
         using namespace Ogre;
+
+        delete this->ccPrintScreen_;
 
         // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
Index: code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.h	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.h	(revision 2344)
@@ -112,4 +112,7 @@
         unsigned int          detailLevelParticle_;      //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
         std::string           defaultMasterKeybindings_; //!< Filename of default master keybindings.
+
+        // console commands
+        ConsoleCommand*       ccPrintScreen_;
     };
 }
Index: code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc	(revision 2344)
@@ -47,4 +47,5 @@
 #include "CameraManager.h"
 #include "LevelManager.h"
+#include "PlayerManager.h"
 #include "Settings.h"
 
@@ -99,4 +100,5 @@
             // create the global LevelManager
             this->levelManager_ = new LevelManager();
+            this->playerManager_ = new PlayerManager();
 
             // reset game speed to normal
@@ -114,8 +116,10 @@
             FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
             functor1->setObject(this);
-            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
+            ccKeybind_ = createConsoleCommand(functor1, "keybind");
+            CommandExecutor::addConsoleCommandShortcut(ccKeybind_);
             FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
             functor2->setObject(this);
-            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
+            ccTkeybind_ = createConsoleCommand(functor2, "tkeybind");
+            CommandExecutor::addConsoleCommandShortcut(ccTkeybind_);
             // set our console command as callback for the key detector
             InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
@@ -130,5 +134,6 @@
             FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
             functor->setObject(this);
-            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
+            ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
+            CommandExecutor::addConsoleCommandShortcut(ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
         }
     }
@@ -136,4 +141,9 @@
     void GSLevel::leave()
     {
+        // destroy console commands
+        delete this->ccKeybind_;
+        delete this->ccSetTimeFactor_;
+        delete this->ccTkeybind_;
+
         // this call will delete every BaseObject!
         // But currently this will call methods of objects that exist no more
@@ -156,4 +166,7 @@
         if (this->levelManager_)
             delete this->levelManager_;
+
+        if (this->playerManager_)
+            delete this->playerManager_;
 
         if (Core::showsGraphics())
Index: code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h	(revision 2344)
@@ -70,4 +70,5 @@
         CameraManager*        cameraManager_;
         LevelManager*         levelManager_;
+        PlayerManager*        playerManager_;
 
         //##### ConfigValues #####
@@ -75,4 +76,9 @@
         //! Filename of default keybindings.
         std::string           defaultKeybindings_;
+
+        // console commands
+        ConsoleCommand*       ccKeybind_;
+        ConsoleCommand*       ccTkeybind_;
+        ConsoleCommand*       ccSetTimeFactor_;
 
     private:
Index: code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc	(revision 2344)
@@ -40,4 +40,5 @@
 #include "core/TclBind.h"
 #include "core/TclThreadManager.h"
+#include "core/LuaBind.h"
 #include "tools/Timer.h"
 #include "objects/Tickable.h"
@@ -87,4 +88,7 @@
         // creates the class hierarchy for all classes with factories
         Factory::createClassHierarchy();
+
+        // Create the lua interface
+        this->luaBind_ = new LuaBind();
 
         // instantiate Settings class
@@ -117,15 +121,19 @@
         FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame);
         functor1->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit"));
+        ccExit_ = createConsoleCommand(functor1, "exit");
+        CommandExecutor::addConsoleCommandShortcut(ccExit_);
 
         // add console commands
         FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState);
         functor2->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState"));
+        ccSelectGameState_ = createConsoleCommand(functor2, "selectGameState");
+        CommandExecutor::addConsoleCommandShortcut(ccSelectGameState_);
     }
 
     void GSRoot::leave()
     {
-        // TODO: remove and destroy console commands
+        // destroy console commands
+        delete this->ccExit_;
+        delete this->ccSelectGameState_;
 
         delete this->shell_;
@@ -133,6 +141,6 @@
         delete this->tclBind_;
 
-        delete settings_;
-
+        delete this->settings_;
+        delete this->luaBind_;
     }
 
Index: code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h	(revision 2344)
@@ -59,4 +59,9 @@
         TclThreadManager*     tclThreadManager_;
         Shell*                shell_;
+        LuaBind*              luaBind_;
+
+        // console commands
+        ConsoleCommand*       ccExit_;
+        ConsoleCommand*       ccSelectGameState_;
     };
 }
Index: code/branches/objecthierarchy2/src/orxonox/gui/GUIManager.cc
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/gui/GUIManager.cc	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/gui/GUIManager.cc	(revision 2344)
@@ -96,13 +96,13 @@
         {
             // destroy our own tolua interfaces
-	        //lua_pushnil(luaState_);
-	        //lua_setglobal(luaState_, "Orxonox");
-	        //lua_pushnil(luaState_);
-	        //lua_setglobal(luaState_, "Core");
+	        lua_pushnil(luaState_);
+	        lua_setglobal(luaState_, "Orxonox");
+	        lua_pushnil(luaState_);
+	        lua_setglobal(luaState_, "Core");
             // TODO: deleting the script module fails an assertation.
             // However there is not much we can do about it since it occurs too when
             // we don't open Core or Orxonox. Might be a CEGUI issue.
             // The memory leak is not a problem anyway..
-            //delete scriptModule_;
+            delete scriptModule_;
         }
 
Index: code/branches/objecthierarchy2/src/orxonox/objects/Script.cc
===================================================================
--- code/branches/objecthierarchy2/src/orxonox/objects/Script.cc	(revision 2256)
+++ code/branches/objecthierarchy2/src/orxonox/objects/Script.cc	(revision 2344)
@@ -64,7 +64,7 @@
   void Script::execute()
   {
-    LuaBind* lua = LuaBind::getInstance();
-    lua->loadString(this->code_);
-    lua->run();
+    LuaBind& lua = LuaBind::getInstance();
+    lua.loadString(this->code_);
+    lua.run();
   }
 }
