Fix code and tests.