refactored main scraper code