Check that the index is in bounds before selecting it