fix dependency between sorting and deleting