Sort Function implemented and updated setSelected