finished code for exercise 1