[IMP]modeify sorting using toggle function, removed unneccesary statments