Adding better detection of NAN