Optimize the template