Implements cached matrix