Implementation and tests