Fixed matrix interface and added a bunch of tests