Add some logging, and a couple of minor fixes