Completed implementation of the cache matrix