This could be moved up above the new_idx and old_idx lines.