Improved template.get function