Implementation and a few tests.