Ok, so basically I just edited the code that caches the mean in the assignment, and change it to calculate the inverse.

Nearly got the whole thing wrong.

Well, here it is.
Typo error in the setinverse, setinvese. Thanks original assignment!

Added more comments. hopefully it's more comprehensible.