better message count logic