better implementation of checking for NaN