add code of chapter 6