Refactoring 'Lexer' and adding code contracts