Move tree_depth() closer to point of use.