Remove explicit type checks from to_key_val_list and from_key_val_list