Add total calculation function