added fallback if tmp file could not be deleted