Added body for matrix caching functions