Refactored data ingestion code