Improve tree template intregration