Refactor. Tests pass.