Fixed the sorting bug