made the tokenize function to clean up code