Changes to fix the bug of -nan when using tokens