finish chapter 12

with code review and improvement from chapter 10~12.