fix bug when sort order was wrong