Would it make more sense to put this logic in `to_dict`?