Improved delete logic