refactorings and tests