more Refactoring of Matrix func