Adds counter and fixes few bugs