Switch to using a breadth-first traversal of the tree.