Changed way of publishing to use setImmediate instead of setInterval