Reduce heap allocations in lexer.

Mostly refactoring/cleaning up the code.