Fix nested matrix multiplication. Closes #705