Fix dequeueing logic a bit.