Fix a sorting bug