private static void downloadTables(WebDriver driver, String folder, String startUrl, String currentLinkText, EnumSet<OutputType> types, String[] newWindows) throws InterruptedException {
		// Begin download
        
		for(OutputType type: types) {
			new File(output_dir, folder+"/"+type.name).mkdirs();
		}
		
    	Pattern pat = Pattern.compile("\\d+-\\d+[A-Z]?");
    	
        // First, save the current page
        driver.switchTo().window(newWindows[0]);
        driver.get(startUrl);

        (new WebDriverWait(driver, 60)).until(ExpectedConditions.presenceOfElementLocated(By.tagName("table")));
        
        for(WebElement h2 : driver.findElements(By.cssSelector("h2"))) {
            String header = h2.getText();
            Matcher m = pat.matcher(header);
            if(m.find()) {
                for(OutputType type: types) {
                    String finalName = m.group() + type.ext;
                    File finalOutput = new File(output_dir, folder+"/"+type.name+"/"+finalName);
                    if(!finalOutput.exists()) {
                        type.download(driver, finalOutput);
                    }
                }
                break;
            }
            else {
                System.err.println("header ignored: "+header);
            }
        }
        
		
        // Click each link if not downloaded yet
        for (WebElement link : driver.findElements(By.partialLinkText("`qި-"))) {
            Matcher m = pat.matcher(link.getText());
        	if(!m.find()) {
        		System.err.println("link ignored: "+link.getText());
        		continue;
        	}
        	
        	String tableId = m.group();
        	
        	boolean pageLoaded = false;
        	
        	for(OutputType type: types) {
            	String finalName = tableId+type.ext;
            	File finalOutput = new File(output_dir, folder+"/"+type.name+"/"+finalName);
    			
            	if(finalOutput.exists())
            		continue;
            	
            	if(!pageLoaded) {
                	String url = link.getAttribute("href");
                    driver.switchTo().window(newWindows[1]);
                    driver.get(url);
                    
                    (new WebDriverWait(driver, 60)).until(ExpectedConditions.presenceOfElementLocated(By.tagName("table")));
                    ((JavascriptExecutor)driver).executeScript(
                    		"var imgs = document.getElementsByTagName('img'); " +
                    		"var len=imgs.length; " +
                    		"for(var i=len-1; i>=0; i--) {imgs[i].parentNode.removeChild(imgs[i]);} ");
                    
                    pageLoaded = true;
            	}
            	
            	type.download(driver, finalOutput);
                
        	}
        	if(pageLoaded) {
                driver.switchTo().window(newWindows[0]);
        	}
//            break;
		}
	}