small refactorings, improved logging