Fixed token end checking bug