Refactored the caching behaviour