Make token name comparison a robust and reusable function