Use setImmediate instead of process.nextTick for recursive calls