Improved selection handling