added code appendix, minor changes