working implementation that caches