Fix problem with to_dict