Matrix+tests (after review)

The patches with changes from the review