Correctly builds the index file