How did galaxies form in the early universe?