fix bug in minmax reported by Wei Chong Tan