Debug tools

This ports some debug tools from #55 into the main branch. 

I intend to use them to fix some basic issues before returning to #55's issue.