Fix bugs in typechecker and lexer, update tests