QuickCheck properties and some bug fixes

We've started looking at the code with Andrew and found some issues. We're still developing the tests though, so there might be more bugs coming :-).

cc @JonMeredith @JTuple