Guard against out of range index values