Exercise 3 solution cleaned