Changed if to while in cache