Fix indexing issue when index > group length