Avoid blowing up the stack by using `setImmediate()` instead of recursion