Fix sqrt of negative values producing NaN.