finish the sorting