better exit condition for recursion