Improved template compiler