improved NaN detection, docs and tests