replaced ternary operator with min/max in couple of places.