Updated logic to allow recursion to end early with params.end = true