Lexer refactoring

Do not merge, please.