Improve caching, bugfixes