cleanup and handling for IOerrors