Tests and refactorings