my solution to exercise 4