clean and fix delete function