refactor load_doc function