Refactored and enhanced the delete() method