fix a sorting bug