def _flatten(d):
    """ Pack a hierarchical dictionary of variables into a list
        Sorting is important as it ensures the function is called with 
        the inputs in the same order each time!
    """
    l = []
    # This sorting is important!
    for (k,v) in sorted(d.items(), key=lambda t: t[0]):
        if isinstance(v, dict):
            lv = _flatten(v)
            for v2 in lv:
                l.append(v2)
        else:
            l.append(v)
    return l