Added checks for NaN