implemented selection inversion