Refactored parser, fixed bugs