def findCompleteFragments(fragments, max_dist, current_position, max_collapse_dist=20):
    """Find complete fragments that are >max_dist bp away from
    the current BAM file position

    Parameters
    ----------
    fragments : dict
        A dictionary containing ATAC fragment information
    max_dist : int
        The maximum allowed distance between fragment start and
        end positions
    current_position : int
        The current position being looked at in the position-sorted
        BAM file
    max_collapse_dist : int
        Maximum allowed distance for fragments from the same cell
        barcode that share one Tn5 integration site (fragment
        start or end coordinate) to be collapsed into a single
        fragment.

    Moves completed fragments to a new dictionary
    Completed fragments will be deleted from the original dictionary
    """
    allkey = list(fragments.keys())
    completed = dict()
    d = max_dist + max_collapse_dist
    for key in allkey:
        if fragments[key][4]:  # complete fragment
            if (fragments[key][2] + d) < current_position:
                completed[key] = fragments[key][:-1]  # removes "completed" T/F information
                del fragments[key]
        else:
            # remove incomplete fragments that are
            # too far away to ever be complete
            if fragments[key][1] is None:
                if (fragments[key][2] + d) < current_position:
                    del fragments[key]
            elif fragments[key][2] is None:
                if (fragments[key][1] + d) < current_position:
                    del fragments[key]
            else:
                # start and end coordinates present without a cell barcode
                del fragments[key]
    return completed