Updated chapter 4 final code.