Fix matrix; add matrix tests