fixed issues in nan checking