added barriers to average counting