modified Matrix multiply to take number of matrices as a parameter