Consolidate common code for data generation scripts