def hierarchical_map_vals(func, node, max_depth=None, depth=0):
    if not hasattr(node, 'items'):
        return func(node)
    elif max_depth is not None and depth >= max_depth:
        return map_dict_vals(func, node)
    else:
        keyval_list = [(key, hierarchical_map_vals(func, val, max_depth, depth + 1)) for key, val in node.items()]
        if isinstance(node, OrderedDict):
            return OrderedDict(keyval_list)
        else:
            return dict(keyval_list)