Fixes some bugs and adds more verbose logging