if (pairs.size()==1) { return (Pair)pairs.firstKey(); }
    private Pair findSmallest() {	Pair smallest=(Pair)pairs.firstKey();	int work=smallest.work;	ArrayList temp=new ArrayList();	boolean cont;	do {	    cont=false;	    temp.add(smallest);	    pairs.remove(smallest);	    Pair newPair=(Pair)pairs.firstKey();	    int newWork=newPair.work;	    if(newWork==work) {		SIRContainer parent1=smallest.n1.filter.getParent();		SIRContainer parent2=newPair.n1.filter.getParent();		if(parent1==parent2) {		    double half=((double)(parent1.size()-1))/2;		    double dist1=Math.abs(half-parent1.indexOf(smallest.n1.filter));		    double dist2=Math.abs(half-parent1.indexOf(newPair.n1.filter));		    if(dist1<dist2) {			cont=true;			smallest=newPair;			work=newWork;		    }		}	    }	} while(cont);	Object[] fix=temp.toArray();	for(int i=0;i<fix.length;i++)	    pairs.put(fix[i],null);	return smallest;    }