Improvement of the magnetic configuration in the reversed field pinch through successive bifurcations