inverted matrix caching function included