Refactoring Token generation