use istringstream to do split on token
minor changes, constness and use string as a parameter