Fix and add tests for parsing code