Average function using template has added