make sure keys are strings before sorting by length