changed setImmediate to setTimeout for compatibility with node v0.8