fixed a sorting bug