Improve cache-correctness

That is the hotfix, next step is to refactor some parts out into a stand-alone module.