Faster and simpler minmax implementation.