The formation and evolution of massive galaxies