fixed problem with counter by making the function's variable global and allowingit to increment properly