make sure graph iteration is sorted