Move around some NaN handling code