def squash_dict(d, delimiter='/', crunch=False, layers=-1):
    """
    Combine recursively nested dicts into the top level dict by prefixing their
    keys with the top level key and delimiter.
    Use the layers parameter to limit the recursion depth.
    Adding the prefixed keys could collide with keys already in the
    top level dictionary, use crunch to suppress errors and replace the
    top level keys when this happens.
    """
    dout = {}
    for k, v in d.items():
        if isinstance(v, dict) and layers != 0:
            for vk, vv in squash_dict(v, delimiter, crunch, layers - 1).items():
                new_key = k + delimiter + vk
                if not crunch and new_key in d.keys():
                    raise Exception("Collision when squashing dict.")
                dout[new_key] = vv
        else:
            dout[k] = v
    return dout