first version exercise 17
updated and shortened version of exercise 17