Handle all edge cases of empty and non empty docs [fixes 67871530 60450016]