Fixing greedy bug