better template handling