Integrated Delete function with the existing code.