Implement hit counters

This set of commits implements hit counters, as suggested in issue #23.

The main commit is 00c95af83b6aee131ab2970abb9cc9f5d030a094, the rest are fixes to the surrounding template.