improvement to setTemplate