Refactoring dict_to_obj and obj_to_dict