add protection against nan in divergence