Refactored code for use with the extraction pipeline