Updated Chapter 4 code