minor fixes on the reader and added error recovery to the writer