Better checking of selected index