Updating to use setImmediate instead of nextTick