update math/max math/min: refactor, using template