Improved template output generation