initial version of a 'stats' middleware. (a better name is likely in order)