Fix totals calculation