Improved code at templates