Implemented the parsing and fixed a number of bugs