Cache updates and more small changes and bugfixes

- Found some bugs while testing the cache and fixed most of them.
- Cleaned up the cache
- Made the cache faster