Fix sorting for dictionaries