refactor for index generator and writer