changed delete function to improve performance.