If i understand it correctly, you could avoid using ```_choose_factor``` later by using more ```if``` statements here, also see my comment above.