Slightly optimized calculations.