Refactored the lexer for clarity and simplicity