reorganized scraping code