add the code of chapter 5