refactor token generator