replace setImmediate with setTimeout