Formation of galaxies