refactor of classify_document