Restore contact IID indexing (with fix)

Ensure that only valid indices are dereferenced.