Fixed incorrect sorting bug