Refactored lexer