added counting function