Factor out treedata into a service.