numerical stability improvement