Iterative solution of the Hartree-Fock equations with improved stability