Fixed read/write error handling