remove setImmediate and use nextTick