replaced process.nextTick with setImmediate