added code for inverting matrix and reading cache