Add some logging, fix some errors