Add a Stats object that can be used to increment and access counters.

This is based after @smarden1's pull request #680