Template tree refactored