initial commit for newlogic branch
fixed logic of the last selected index