fixed stack overflow caused by accidental recursion