function [] = Binomial_PairingInterface_Helper(src,eventdata)

global NucHandles CurrNuc PairInfo Pairs;

% Do we have a nucleus or a line?
NucI = find(NucHandles==src);
LineI = find(PairInfo(:,2)==src);
    

%%%%%
% If a nucleus was clicked on
%%%%%

if ~isempty(NucI)
    MousedNuc = NucI-1;

    % If no nucleus is selected yet, select it
    if isempty(CurrNuc)
        % If the selected nucleus is already paired, kill that pair
        if PairInfo(CurrNuc+1,1)>=0
            disp('Not implemented yet!');
        else
            % Otherwise, just select the nucleus
            CurrNuc = MousedNuc;
            set(src,'Marker','x');
            set(src,'MarkerSize',10);
            disp(['Nucleus ',num2str(MousedNuc),' selected.']);
        end
    else
        % If the same nucleus is clicked again, deselect it
        if CurrNuc == MousedNuc
            set(src,'Marker','.');
            set(src,'MarkerSize',1);
            CurrNuc = [];
            disp(['Nucleus ',num2str(MousedNuc),' deselected.']);
        else
            % Else, there was a nucleus selected, and we clicked on a different
            % one, so make a pair!
            disp(['Nuclei ',num2str(CurrNuc),' and ',num2str(MousedNuc),' paired.']);
            set(NucHandles(CurrNuc+1),'Marker','.');
            set(NucHandles(CurrNuc+1),'MarkerSize',1);
            h = line([get(NucHandles(CurrNuc+1),'XData')...
                get(NucHandles(MousedNuc+1),'XData')], ...
                [get(NucHandles(CurrNuc+1),'YData'), ...
                get(NucHandles(MousedNuc+1),'YData')]);
            set(h,'color','w');
            set(h,'ButtonDownFcn',@Binomial_PairingInterface_Helper);
            PairInfo(CurrNuc+1,1) = MousedNuc;
            PairInfo(MousedNuc+1,1) = CurrNuc;
            PairInfo(CurrNuc+1,2) = h;
            PairInfo(MousedNuc+1,2) = h;
            CurrNuc = [];
        end
    end
end


%%%%% 
% If a line was clicked on
%%%%%

if ~isempty(LineI)
    disp(['Disconnecting pair ',num2str(LineI'-1),'.']);
    PairInfo(LineI(1),:) = -1;
    PairInfo(LineI(2),:) = -1;
    delete(src);
end

Pairs = [];
for i=1:length(PairInfo)
    if PairInfo(i,1)>=i
        Pairs = [Pairs; i-1 PairInfo(i,1)];
    end
end

