added lock for counters flush