fix rev
improve pmin and pmax