Refactor to pass all tests.