Various fixes and better logging