diff --git a/src/utility/nlsr_tokenizer.cpp b/src/utility/nlsr_tokenizer.cpp
index 809e395..35d6625 100644
--- a/src/utility/nlsr_tokenizer.cpp
+++ b/src/utility/nlsr_tokenizer.cpp
@@ -9,102 +9,102 @@
 namespace nlsr
 {
 
-    using namespace std;
-    using namespace boost;
+  using namespace std;
+  using namespace boost;
 
-    void
-    nlsrTokenizer::makeToken()
+  void
+  nlsrTokenizer::makeToken()
+  {
+    char_separator<char> sep(seps.c_str());
+    tokenizer< char_separator<char> >tokens(originalString, sep);
+    tokenizer< char_separator<char> >::iterator tok_iter = tokens.begin();
+    for ( ; tok_iter != tokens.end(); ++tok_iter)
     {
-        char_separator<char> sep(seps.c_str());
-        tokenizer< char_separator<char> >tokens(originalString, sep);
-        tokenizer< char_separator<char> >::iterator tok_iter = tokens.begin();
-        for ( ; tok_iter != tokens.end(); ++tok_iter)
-        {
-            string oneToken(*tok_iter);
-            trim(oneToken);
-            if(!oneToken.empty())
-            {
-                insertToken(oneToken);
-            }
-        }
-        firstToken=vTokenList[0];
-        makeRestOfTheLine();
+      string oneToken(*tok_iter);
+      trim(oneToken);
+      if(!oneToken.empty())
+      {
+        insertToken(oneToken);
+      }
     }
+    firstToken=vTokenList[0];
+    makeRestOfTheLine();
+  }
 
-    void
-    nlsrTokenizer::insertToken(const string& token)
-    {
-        tokenList.push_back(token);
-        vTokenList.push_back(token);
-    }
+  void
+  nlsrTokenizer::insertToken(const string& token)
+  {
+    tokenList.push_back(token);
+    vTokenList.push_back(token);
+  }
 
-    int
-    nlsrTokenizer::getTokenPosition(string& token)
+  int
+  nlsrTokenizer::getTokenPosition(string& token)
+  {
+    int pos=-1;
+    int i=0;
+    for(std::list<string>::iterator it=tokenList.begin();
+        it!=tokenList.end(); it++)
     {
-        int pos=-1;
-        int i=0;
-        for(std::list<string>::iterator it=tokenList.begin();
-                it!=tokenList.end(); it++)
-        {
-            if( (*it) == token )
-            {
-                break;
-            }
-            i++;
-        }
-        if( i < tokenList.size() )
-        {
-            pos=i;
-        }
-        return pos;
+      if( (*it) == token )
+      {
+        break;
+      }
+      i++;
     }
+    if( i < tokenList.size() )
+    {
+      pos=i;
+    }
+    return pos;
+  }
 
-    string
-    nlsrTokenizer::getTokenString(int from , int to)
+  string
+  nlsrTokenizer::getTokenString(int from , int to)
+  {
+    string returnString="";
+    if((from>=0 && to<tokenList.size()) &&
+        (to>=from && to <tokenList.size()))
     {
-        string returnString="";
-        if((from>=0 && to<tokenList.size()) &&
-                (to>=from && to <tokenList.size()))
-        {
-            for(int i=from; i<=to; i++)
-            {
-                returnString+=seps;
-                returnString+=vTokenList[i];
-            }
-        }
-        trim(returnString);
-        return returnString;
+      for(int i=from; i<=to; i++)
+      {
+        returnString+=seps;
+        returnString+=vTokenList[i];
+      }
     }
+    trim(returnString);
+    return returnString;
+  }
 
-    string
-    nlsrTokenizer::getTokenString(int from)
-    {
-        return getTokenString(from,tokenList.size()-1);
-    }
+  string
+  nlsrTokenizer::getTokenString(int from)
+  {
+    return getTokenString(from,tokenList.size()-1);
+  }
 
-    static bool
-    tokenCompare(string& s1, string& s2)
-    {
-        return s1==s2;
-    }
+  static bool
+  tokenCompare(string& s1, string& s2)
+  {
+    return s1==s2;
+  }
 
-    void
-    nlsrTokenizer::makeRestOfTheLine()
-    {
-        restOfTheLine=getTokenString(1);
-    }
+  void
+  nlsrTokenizer::makeRestOfTheLine()
+  {
+    restOfTheLine=getTokenString(1);
+  }
 
-    bool
-    nlsrTokenizer::doesTokenExist(string token)
+  bool
+  nlsrTokenizer::doesTokenExist(string token)
+  {
+    std::list<string >::iterator it = std::find_if( tokenList.begin(),
+                                      tokenList.end(),
+                                      bind(&tokenCompare, _1 , token));
+    if( it != tokenList.end() )
     {
-        std::list<string >::iterator it = std::find_if( tokenList.begin(),
-                                          tokenList.end(),
-                                          bind(&tokenCompare, _1 , token));
-        if( it != tokenList.end() )
-        {
-            return true;
-        }
-        return false;
+      return true;
     }
+    return false;
+  }
 
 }//namespace nlsr
