fixed index assignment bug