Astronomers close to solving how galaxies formed