Improvements to caching, more tests.