Handle NaNs and Infinite values.