refactored totaling