Improved caching (todo: test)