Adds more checks before deleting temporary files.