implementing min max reduce