function mls_cleanup(varargin)
if nargin>=1
    imagename=varargin{1};
else
    imagename=spm_get(Inf,'*.img*',{'Select images to delete'});
end
if nargin>=2 & isstr(varargin{2})
    filtr=varargin{2};
else
    filtr='*.img';    
end
if ~exist('imagename','var')
    imagename=spm_get(Inf,filtr,{'Select images to delete'});
end
if ~nargin
    a='n';
end
if ~iscellstr(imagename)
  mls_cleanup({imagename})
else
  for i=1:length(imagename)
    if ~exist(imagename{i},'file')
      disp(['WARNING!!!'])
      disp(['file not found: ',imagename{i}])
      disp(['pwd = ',pwd])
      continue
    end
    
    [pth,nam,ext] = fileparts(imagename{i});
    if strcmpi(ext,'.bz2')
      [pth,nam,ext]=fileparts(fullfile(pth,nam));
      ad ='.bz2';
    else
      ad='';
    end
    %if strcmp(pth,'')
    %    error('pth unknown')
    %end
    if strcmp(ext,'.img')
      tmp1={fullfile(pth,[nam, ext]),fullfile(pth,[nam, '.hdr']), fullfile(pth,[nam, '.mat'])};
    else
      tmp1={fullfile(pth,[nam, ext])};
    end
    if ~nargin | strcmpi(filtr,'SAFEMODE')
        if ~exist('a','var')
            a='n';
        end
      if ~strcmpi(a,'all')
	disp(['about to delete ',imagename{i}])
	a=input('are you sure [yes/no/all] ?','s');
      end
      if strcmpi(a(1),'y') | strcmpi(a,'all')
	for t=1:length(tmp1)
	  if exist(tmp1{t},'file')
	    delete(tmp1{t})
	  else
	    disp([tmp1{t},' not found'])
	  end
	end
      else
	disp('aborting !')
	continue
      end
    else
      for t=1:length(tmp1)
            if exist(tmp1{t},'file')
	      delete(tmp1{t})
            else
	      disp([tmp1{t},' not found'])
            end
      end
    end
  end
end