implemented selection loop deletion logic