exercise 3 solution - updated versions