Added chapter 4 and appendix 3.