Improved error detection in the lexer