changing setTimeout to process.nextTick