def combine_lines(components, element_list, background):
    """
    Combine results for different lines of the same element.
    And also add pileup, userpeak, background, compton and elastic.

    Parameters
    ----------
    components : dict
        output results from lmfit
    element_list : list
        list of elemental lines
    background : array
        background calculated in given range

    Returns
    -------
    dict :
        combined results for elements and other related peaks.
    """
    new_components = {}
    for e in element_list:
        if len(e) <= 4:
            e_temp = e.split("_")[0]
            intensity = 0
            for k, v in components.items():
                if (e_temp in k) and (e not in k):
                    intensity += v
            new_components[e] = intensity
        elif "user" in e.lower():
            for k, v in components.items():
                if e in k:
                    new_components[e] = v
        else:
            comp_name = "pileup_" + e.replace("-", "_") + "_"  # change Si_K-Si_K to Si_K_Si_K
            new_components[e] = components[comp_name]

    # add background and elastic
    new_components["background"] = background
    new_components["compton"] = components["compton"]
    new_components["elastic"] = components["elastic_"]
    return new_components