Revert "Revert changes in how tree data is generated."

This reverts commit b21bc08560fa347ea0e0b3e3a1d22a01ac9f2889.
Revert "Start fixing layout to use a tree structure."

This reverts commit 0c5a3f3d3b970dd734bcf5ac110b04bcffc88f68.