add test & refactoring