refactor to_dict