Memoize function. Needs work to allow clearning