Move greedy algorithm to factory.