initial refactor of the caching stuff