template optimization