Refactor the cache to puts things at the right place