Fixing setSelection function