def extractLeafsAndIntBranches( nt, options, leafDict ):
    """Given a newick tree object, it returns a dict of
    leaf and internal branch objects. Operates recursively.
    """
    if nt is None:
        return None
    nt.distance = 0
    if nt.right is None and nt.left is None:
        # leaf
        leafDict[ nt.iD ] = True
    else:
        if options.internalBranches:
            if nt.right is not None and nt.left is not None and nt.iD != options.rootName:
                # internal branch
                leafDict[ nt.iD ] = True
        extractLeafsAndIntBranches( nt.right, options, leafDict = leafDict )
        extractLeafsAndIntBranches( nt.left , options, leafDict = leafDict )