Refactor tokenization