min max refact