change index type from int to size_t