refactor and add test
test completed