refactor for test and add test