Minor refactoring, added custom logging