handling write errors