only calculate sums if needed