Handle potential NaN issue