Refactoring and adding a test case