Created a cachable matrix function
Added additional comments