how are galaxies formed