Extended tree output to work with internal fragments

This simplifies the tree building code