The previous code was a lot cleaner but caused 1+N (where N is the dimension of the matrix) on each multiply.