WIP: make matrix cleverer.
WIP: continued cleverization of matrix. currently broken.