Remove repetitive code in fn-max and fn-min