Stabilizing the generalized Schur algorithm