Improve caching and minor fixes