Use a more elegant method of detecting NaN