With the evolution of the Ditrysia in the mid-Cretaceous, there was a major reproductive change. The Ditrysia, which comprise 98% of the Lepidoptera, have two separate openings for reproduction in the females (as well as a third opening for excretion), one for mating, and one for laying eggs. The two are linked internally by a seminal duct. (In more basal lineages there is one cloaca, or later, two openings and an external sperm canal.) Of the early lineages of Ditrysia, Gracillarioidea and Gelechioidea are mostly leaf miners, but more recent lineages feed externally. In the Tineoidea, most species feed on plant and animal detritus and fungi, and build shelters in the larval stage.