using the prioirty queue