added some selected index logic