Formation of galaxies and galaxy clusters