diff --git a/libcorpus2_whole/corpus.h b/libcorpus2_whole/corpus.h
index b4ca6e812738e5179ead9023d1907eea2434f3a2..225018ca1f3412388f61159a8650c61266c60a56 100644
--- a/libcorpus2_whole/corpus.h
+++ b/libcorpus2_whole/corpus.h
@@ -50,23 +50,22 @@ public:
 
 	/// Next document in corpus
 	boost::shared_ptr<Document> next_document() {
-		boost::shared_ptr<Document> _empty_doc_ptr;
+		static boost::shared_ptr<Document> _empty_doc_ptr;
 		if (!this->set_) {
 			if (this->documents_.size() == 0) {
 				return _empty_doc_ptr;
 			}
-
 			this->set_ = true;
 			this->current_document_ = documents_.begin();
 		}
 		else {
-			if (current_document_ == documents_.end()) {
-				return _empty_doc_ptr;
-			}
-
 			current_document_++;
 		}
 
+		if (current_document_ == documents_.end()) {
+			return _empty_doc_ptr;
+		}
+
 		return *current_document_;
 	}