restructured cache-history code