Replace process.nextTick by setImmediate