Write error checking fixed