added calculation of totals