refactor std::min/std::max