modified to read from index