Do not count messages when it is not needed.
Optimized counting. Added <opt_count/> (for testing).