fixed flaw in the cache logic