implement safe cleanup of temporary files