adding logic of counting