Factored out template rendering