Add caching and other speed optimizations