Switch from setTimeout to process.nextTick