Added cacheElements function