Fix bug in _choose_factor