Fixing NaN comparison, using Double.isNan, rathern than !=