Added the tree_check code