rewrote the parser to be more sound, added error handling