Fix greedy logic.