Optimization of Templates class