Why are you assigning minVal to maxVal in the following code?
That was probably my fat-fingered mistake.