def update_sample_for_autocreated_cohorts(instance, created, **kwargs):
    "Manages adding/removing samples from autocreated cohorts."

    # World
    lookup = {'batch': None, 'project': None, 'autocreated': True,
              'name': 'World'}
    try:
        world_cohort = Cohort.objects.get(**lookup)
    except Cohort.DoesNotExist:
        if getattr(settings, 'VARIFY_AUTO_CREATE_COHORT', True):
            world_cohort = Cohort(**lookup)
            world_cohort.save()
        else:
            log.info("World cohort was not found and was not created because "
                     "VARIFY_AUTO_CREATE_COHORT setting is False.")
            return

    project = instance.project

    # Project
    lookup = {'batch': None, 'project': project, 'autocreated': True}
    try:
        project_cohort = Cohort.objects.get(**lookup)
    except Cohort.DoesNotExist:
        project_cohort = Cohort(name=unicode(project), **lookup)
        project_cohort.save()

    if instance.published:
        world_cohort.add(instance, added=False)
        project_cohort.add(instance, added=False)
    else:
        world_cohort.remove(instance, delete=True)
        project_cohort.remove(instance, delete=True)