Handling parse errors without crashing

Fix for #8 and a bunch of other stuff.