Unit Test and small refactorings