Refactor and clean up the extract module.