Added memoize, other small changes.