refactored lexer.lua