Fixed bug in histograms sorting