sorting of keys on comparison result