improved selection handling