added in counter to keep track of program flow and adjust the speed