converted sum to general reduction
added minVal, maxVal and minMaxVal functions