Implemented cached matrix