added appendix D, with code from book I used