add test & refactor