Implemented the cachematrix functionality.