matrix inversion complete
updated caching code