Fix a bug in safe factorization mode