2x speedup with additional memoization