Added an appendix, formatted source code and did some other changes.