added chapter 3 and an appendix on threshold functions