Modified so that it will change selectedIndex