factor out text extraction