Robust wave function optimization procedures in quantum Monte Carlo methods