A bug in the counting logic