small refactoring, add logging