shorter memoization version by Varyform