improved tokenize algorithm to use STL library