Minor, but significant improvements to template handling.