utf8 safe function for tokenization