Matrix inversion and cache functions inserted