Making check_tree function