replace process.nextTick with setImmediate