Clean-up example
Refactor caching, use memoization techique