changed cache logic slightly