ensure all keys are sorted