fixed bugs occuring when counter is 0.