Fix sortperm for new sort API