def METHOD_NAME(results):
    # filter off the DeferredList results (we know it's good)
    results = [r[1] for r in results]
    # filter for masterid
    if masterid is not None:
        results = [r for r in results
                   if r['masterid'] == masterid]
    # filter for active or inactive if necessary
    if active:
        results = [r for r in results
                   if r['masterid'] is not None]
    elif active is not None:
        results = [r for r in results
                   if r['masterid'] is None]
    return results