Slight rewriting of Valmax so MSVC is happier