Handle write and read errors.
Merge pull request #18 from larzconwell/handle-write-err

Handle write and read errors.