small refactorings and fixes