changed process.nextTick to setImmediate