refactor of extract_from_files to be more reusable