Fixed bug comparing to nan