Refactor as function.
Add test.