Update for Matrix

Extend the original code