modularized the lexer and fixed a bug in it