Refactor. Add test.