fixed the sorting bug