Backport fix from master: fixed index access