added indexing logic