Fixed bugs in caching and fixed plotting