min/max calls replaced with std::min/std::max