refactor + add unit test