Improved caching mechanisms + minor fixes.