Added memoize decorator function.