Refactoring and Unit tests