Fix major caching bugs