Refactor how to count valid dates so no double counts

… even if there are duplicate messages, only the first one is counted

Fixes #248
Merge to upstream