Fix sorting and shuffling