added a portion of tree class to check the validity of the tree