Minor refactoring and logging changes