Readded the memoization to the cleaned version, OOM errors for now.