Added a case in the if-clause that handles if the object is the last object in the list and deletes itself.