refactoring and add test cases