Refactoring and adding some caches.
Merge branch 'caching' into develop