ruby 1.8 hash.keys are not ordered, they need sort