Rewrote deletion code

Deletion should be more reliable now.