Fixed minval and maxval issues when one of them is set to 0.