Use setImmediate rather than setTimeout