Fix parsing bug.

Still slow, still uses a lot of memory. However, it is now more
correct.