Optimized calcMinMax