The Rhipidistians, whose ancestors probably lived in the oceans near the river mouths (estuaries), left the ocean world and migrated into freshwater habitats. They in turn split into two major groups : the lungfish and the tetrapods. The lungfish evolved the first proto-lungs and proto-limbs; they learned in the middle Devonian (397–385 mya) how to live outside a water environment, using their stubby fins (proto-limbs) to walk on land and find new water if their waterhole was depleted, and their lungs to breathe air and get sufficient oxygen. The lungfish's greatest diversity was in the Triassic period; today there are fewer than a dozen genera left.