change setTimeout to setImmediate