Fix illegal index panic