Fix refactoring and tests.