Fix sorting issues