fix conditions that lead to NaN and persisted NaN corruption of values