Add some debug check to see where the Inf and NaN comes.