Fix click event bug and sync select and deselect code