add test and refactoring