matrix caching
comments

added comments that describing the function and its sub functions