some safeguards for deletion. also fixed typo that was allowing delete to be attempted more than once