Version with caching implemented