Implemented cachematrix functionality