Implementation and tests.