Sorting bug fix