Safe index in selection grids

Fixes #47.