added safeguard to filedeletion