Replace last process.nextTick with setImmediate