bug fixed for greedy