improved performance for dealing with NaN input data, original fix could not handle 0-d inputs