calculating the totals