Fix issues in general greedy algorithm.