Fix sorting bug