Added caching and minor fixes