Not necessary to check maxVal here (directly managed inside the loop).