safeguard against empty/invalid docs