added memoization of matrix functions