Pull group scraping logic out of if __name__ block and clean up.