Bug fix and more logging