Implementation and quickcheck testing.