using setImmediate instead of process.nextTick