Refactor code. Add test.