def format_leads(leads):
    """For a list of leads, removes the "custom" key from each lead and
    transforms all "custom.* fields into a new "custom_fields" list."""
    new_leads = []
    for lead in leads:
        custom_fields = []
        new_lead = {'custom_fields': custom_fields}
        for k, v in lead.items():
            if k.startswith('custom.'):
                custom_id = k.split('.')[1]
                custom_fields.append({'id': custom_id, 'value': v})
            elif k != 'custom':
                new_lead[k] = v
        new_leads.append(new_lead)
    return new_leads
