add some instrumentation and assertions to debug NaN problem