Further implementation of the matrix math code