First draft of caching the inverse. Needs some work.