fix some numerical instability