lots of duplication here and and the webmachine stats endpoint.  Can that be cleaned up into a set of common functions?