Adding extra code from Chapter 7's exercises