compute indexing header only once
handle empty lines with spaces
reuse docs slice
print out last bulk info
force flush index at the end