Implement extended caching system

Tons of other changes fixes and so on, can't really remember anymore..