caching and other optimizations