Introduce quickcheck and fix found bugs