Various bugs fix

Some bugs fix, especially on selection handling.
Commits message are hopefully explicit enough