totals refactor