hist_sort() modified