Exercise 5
Modified selection handling