Rewrite delete function to make all tests pass