The Miami area was inhabited for thousands of years by indigenous cultures (some villages even dating back to 500-600 B.C) until in 1566 the explorer Pedro Menéndez de Avilés claimed it for Spain. In 1568 a Spanish mission was constructed and Spain as well as Britain controlled Florida successively. Spain ceded it to the United States in 1821. Miami was officially incorporated as a city on July 28, 1896 with a population of just over 300. It was named for the nearby Miami River. Black labor played a crucial role in Miami's early development as nearly 40 percent of the city's population were migrants from the Bahamas. in the early 20th century Miami prospered because northerners got attracted to the city which led to an increase in population and infrastructure. During World War II Miami became a base for US defense against German submarines.