On the energy optimization of the AGP wavefunction. The ground state of the Be atom