Improved template handling.