Minor refactorings and added more consistent logging. Should solve most of #6