improved totaling functionality