Refactor lexer, removing end of input exception