Fixed some rounding error which cause the infinite loop.