Added a function to check whether a string is a valid token.