replace setTimeout with process.nextTick & fixed indentation