Edited to calculate and cache inverse of a matrix