- fixed a bug which makes the function stack overflow in some cases