add:code from chapter 6 to 8