Refactoring and test cases