The initialization of min and max was reversed. Switch to C++ numeric limits, which I'm a bit more used to ad this point.