Write tokenize function