Fixing wrong selectedIndex assignment