Rewrote some of the stuff. Added test for deleting.