Divided logic between lexer and validator.
Added new tests