Add cache optimization, though not quite good right now