Lua/MemoizeOfRecursion: Refactor the memoize function