Fix token generation bug