refactor the parser, added tests