refactoring for better token handling