Major refactor in gathering metrics, and lots of debug logging additions