Use std min/max and make corrections