Moved counter outside the anonymous function