fix a host of calculation bugs, tracing for the totalVals issue