if/else replaced by max/min