Fixing recursion bug