Clean up and memoize