replaces fmin with std::min as per abma's request