Refactorings and more tests