refactored the initial extraction code