added error counters and improved the handling for the various types of read/write errors