adjusting indexing in function