modified greedy to keep queue