fix to handle NaNs