Updated for inverted matrix caching.