Counting the number of occurrences