def reroot(self, tree):
        '''
        Reroot a tree: This small piece of code is intended to take a rooted 
        tree that is NOT binary, that is to say, the root node has 3 or more
        child nodes. To create a binary tree, this function will find the two 
        longest distances between the child nodes, find which child node is 
        common to them both, and reroot at the branch connecting that node 
        to root. For example, the new root will be placed where the "x" is in 
        the following example tree:
                                      _
                                   __|_     _
                                  |_____x__|
                                --|__ _    |_
                                     |_
        
        Parameters
        ----------
        tree: dendropy.Tree
            Tree to be rerooted
            
        Raises
        ------
        BinaryTreeError : If the input tree is already a binary tree

        '''

        children = {x.length:x for x in tree.seed_node.child_edges()}
        tree.is_rooted=True
        
        if len(children) > 2:
            longest_edge_length = max(children.keys())
            longest_edge = children[longest_edge_length]
            tree.reroot_at_edge(longest_edge, 
                                length1=(longest_edge_length/2), 
                                length2=(longest_edge_length/2))
            return tree
        
        elif len(children) == 2:
            raise BinaryTreeError("Tree is already binary. Something has \
-mislead me here!")
        else:
            raise MalformedTreeError("Input tree is malformed")