Fixed a couple of bugs especially that NAN is not ruining the
calculation of the min/max values.