Revised matrix multiplication function