added code from book chapter 1 to 12