Update the code acording to the chapter 2
Updated the chapter 3 code