Adjusted to allow outputting of index