fixed recursion bug