Added computing average lengths and writing reverse index to file