implement total calculation