Changed delete method to integrate with UndoManager