Change to support both distribute and non-distribute calculation.