fix sorting of nodes to be removed