improved logging, small refactoring