add code to delete index after finished
some optimizations