Working the matrix math part