added counting functionality