added some debug code, a few minor fixes to readers/writers that weren't being closed