Exercise 2 code.