Improved NaN Checking.
Merge branch '767_better_nan_checking' into next