use setImmediate instead of nextTick