Some refactorings + additional tests