Changed to prefer setImmediate over process.nextTick