Refactoring and updating unit tests