Changed process.nextTick to setImmediate