Better recursion logic