fix recursion bug