now sorting the dictionary only once