change the index type from int to size_t