Sorting references in traverse