use setImmediate instead of multiple intervals