Refactor/the matrix

Awaiting a few fixes so should be merged just yet.