def _smallest_distance(node):
    """
    Takes a TreeNode object as an input and returns the leaf with with the
    smallest distance to the given node.
    """
    smallest_dist = None
    for leaf in node.iter_leaves():
        dist = leaf.distance_to(node)
        if not smallest_dist or dist < smallest_dist:
            leaf_to_keep = leaf
            smallest_dist = dist
    return leaf_to_keep
