Used StopIteration exception to break out ingestion processing loop in controlled fashion,  Made document sort key safe.