cached matrix implementation v1