Changed to use just a local variable as a counter