Adds part of chap8 code