Counting logic