replace nextTick with setImmediate