added to_safe_dict function