Refactored code added a delete listener