added better template support