Matrix caching functions with more comments