Fix a couple of bugs
Add more logging