Fixed the index function