Final version of cached solve matrix function.