Refactor lexer and input