Index: code/branches/core5/src/libraries/core/Game.cc
===================================================================
--- code/branches/core5/src/libraries/core/Game.cc	(revision 5839)
+++ code/branches/core5/src/libraries/core/Game.cc	(revision 5843)
@@ -457,10 +457,10 @@
     {
         // Split string into pieces of the form whitespacesText
-        std::vector<std::pair<std::string, unsigned> > stateStrings;
+        std::vector<std::pair<std::string, int> > stateStrings;
         size_t pos = 0;
         size_t startPos = 0;
         while (pos < str.size())
         {
-            unsigned indentation = 0;
+            int indentation = 0;
             while(pos < str.size() && str[pos] == ' ')
                 ++indentation, ++pos;
@@ -470,37 +470,45 @@
             stateStrings.push_back(std::make_pair(str.substr(startPos, pos - startPos), indentation));
         }
-        unsigned int currentLevel = 0;
-        shared_ptr<GameStateTreeNode> currentNode = this->rootStateNode_;
-        for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it)
-        {
-            std::string newStateName = it->first;
-            unsigned newLevel = it->second + 1; // empty root is 0
-            if (!this->checkState(newStateName))
-                ThrowException(GameState, "GameState with name '" << newStateName << "' not found!");
-            if (newStateName == this->rootStateNode_->name_)
+        if (stateStrings.empty())
+            ThrowException(GameState, "Emtpy GameState hierarchy provided, terminating.");
+        // Add element with large identation to detect the last with just an iterator
+        stateStrings.push_back(std::make_pair("", -1));
+
+        // Parse elements recursively
+        parseStates(stateStrings.begin(), this->rootStateNode_);
+    }
+
+    /*** Internal ***/
+
+    void Game::parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode)
+    {
+        SubString tokens(it->first, ",");
+        std::vector<std::pair<std::string, int> >::const_iterator startIt = it;
+
+        for (unsigned int i = 0; i < tokens.size(); ++i)
+        {
+            it = startIt; // Reset iterator to the beginning of the sub tree
+            if (!this->checkState(tokens[i]))
+                ThrowException(GameState, "GameState with name '" << tokens[i] << "' not found!");
+            if (tokens[i] == this->rootStateNode_->name_)
                 ThrowException(GameState, "You shouldn't use 'emptyRootGameState' in the hierarchy...");
-            shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode);
-            newNode->name_ = newStateName;
-
-            if (newLevel <= currentLevel)
-            {
-                do
-                    currentNode = currentNode->parent_.lock();
-                while (newLevel <= --currentLevel);
-            }
-            if (newLevel == currentLevel + 1)
-            {
-                // Add the child
-                newNode->parent_ = currentNode;
-                currentNode->children_.push_back(newNode);
-            }
-            else
-                ThrowException(GameState, "Indentation error while parsing the hierarchy.");
-            currentNode = newNode;
-            currentLevel = newLevel;
-        }
-    }
-
-    /*** Internal ***/
+            shared_ptr<GameStateTreeNode> node(new GameStateTreeNode());
+            node->name_ = tokens[i];
+            node->parent_ = currentNode;
+            currentNode->children_.push_back(node);
+
+            int currentLevel = it->second;
+            ++it;
+            while (it->second != -1)
+            {
+                if (it->second <= currentLevel)
+                    break;
+                else if (it->second == currentLevel + 1)
+                    parseStates(it, node);
+                else
+                    ThrowException(GameState, "Indentation error while parsing the hierarchy.");
+            }
+        }
+    }
 
     void Game::loadGraphics()
Index: code/branches/core5/src/libraries/core/Game.h
===================================================================
--- code/branches/core5/src/libraries/core/Game.h	(revision 5839)
+++ code/branches/core5/src/libraries/core/Game.h	(revision 5843)
@@ -143,4 +143,5 @@
         void unloadGraphics();
 
+        void parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode);
         bool checkState(const std::string& name) const;
         void loadState(const std::string& name);
