Moved tempfile removal to defer