fix potential file deletion issue