Fixed template bug with setTemplate()