Refactoring token match functions