fixed a bug where recursion can occur