Changed the way the max and min values are switched.