Experimenting with generic memoization function.