editted to calculate and cache inverse of a matrix