Refactor to make tests pass.