refactor an if block to std::min