keys sort function fixed