def METHOD_NAME(blocks, key, require_format=False, **kwargs):
    """
    Given the blocks, locates the nested blocks matching the criteria set in kwargs.
    Arguments
        blocks          --   Dictionary mapping ID strings to block dicts
        key             --   ID of the root node where tree traversal should begin
        require_format  --   Boolean indicating if the format field should be required to have a
                             non-empty (truthy) value if a match is made
        kwargs          --   Dictionary mapping field names to required values for matches
    """
    block = blocks[key]
    block_type = kwargs.pop('block_type', None)
    if block_type:
        kwargs['type'] = block_type
    matched = True
    for name, value in kwargs.items():
        matched &= (block.get(name, None) == value)
        if not matched:
            break
    if matched:
        if require_format:
            if 'format' in block and block['format']:
                return [block]
        else:
            return [block]
    children = []
    if 'children' in block:
        for child in block['children']:
            children += CourseStructure.METHOD_NAME(blocks, child, require_format=require_format, **kwargs)
    return children