Refactoring and token retrieval