def flat_vars(doc):
    """
    Flat given nested dict, but keep the last layer of dict object unchanged.
    :param doc: nested dict object, consisted solely by dict objects.
    :return: flattened dict, with only last layer of dict un-flattened.
    """
    me = {}
    has_next_layer = False
    for key, value in doc.items():
        if isinstance(value, dict):
            has_next_layer = True
            child, is_final_layer = flat_vars(value)
            if is_final_layer:
                me[key] = child
            else:
                for child_key, child_value in child.items():
                    me["%s.%s" % (key, child_key)] = child_value
        else:
            me[key] = value
    return me, not has_next_layer