Refactor some complexity out of lexer