def get_clean_history(frets, *, window_size, guitar,
                      allow_open=True, distinct_only=False):
    """Create a list with the last ``window_size`` frets
    that match the given constraints.
    The ``frets`` should have the unfiltered history of output frets.
    See the ``find_strings`` documentation
    for more information about the remaining parameters.
    """
    previous = None
    result = []
    for fret in reversed(frets):
        if distinct_only and fret == previous:
            continue
        if allow_open and fret == guitar.min_fret:
            window_size -= 1
        else:
            previous = fret
            result.append(fret)
        if len(result) == window_size:
            break
    return result