fix sorting bug