Improve setTemplate functionality