add test and refactor