Refactoring and first working test