Fixed bug in matrix cache.