Improve debugging helpers and clean up tests a bit.