refactoring and test cases