use setImmediate instead of process.nextTick to be browser-compatible