Fixing bug with matrix caching.