lots of small refactorings