Major bug fixes to cachcing