added counter class and changed most of the code