verified working caching matrix solver