Refactorings and test added