fixed incorrect totals calculation