Working version of cache matrix