Small keysort bug fixed in encode_dict