Refactored delete logic.

Change-Id: I318af8da41a20b87dce317c8dc4c520a05ff795e