Fix matrix assembly.