handle empty documents and better loading