Corrected the index function