finish the code of chapter 6