implemented matrix multiplication function