function bfitcleanup(fighandle, numberpanes)
% BFITCLEANUP clean up anything needed for the Basic Fitting GUI.

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.7 $  $Date: 2000/08/30 23:04:31 $

if ishandle(fighandle) % if figure still open or in the process of being deleted
    datahandle = getappdata(fighandle,'_Basic_Fit_Current_Data');
    if ~isempty(datahandle)
        guistate = getappdata(datahandle,'_Basic_Fit_Gui_State');
        guistate.panes = numberpanes;
        setappdata(datahandle,'_Basic_Fit_Gui_State', guistate);
    end
    set(handle(fighandle), '_Basic_Fit_GUI_Object', []);
	if ~isempty(findprop(handle(fighandle),'_Data_Stats_GUI_Object'))
		bfitguiobj = get(handle(fighandle), '_Data_Stats_GUI_Object');
	else
		bfitguiobj = [];
	end
    if isempty(bfitguiobj) % both gui's gone, reset double buffer state
        set(fighandle,'doublebuffer',getappdata(fighandle,'_bfit_doublebuffer'));    
        rmappdata(fighandle,'_bfit_doublebuffer'); % remove it so we set doublebuffer on if reopen gui
    end
% reset normalized?
end

