Added runtime checks for matrix multiplications