Back-end cleanup and optimization in the lexer